Panagiotis Sakkis February 2016

How to add an effect on QGraphicsView?

I'm trying to add a blur effect on my graphicsView but i have to trigger the action twice to apply the effect.The first time i trigger it, it applies the effect on the graphicsView's borderline and on the second trigger it applies it on the scene.Here is my code(the same with colorize effect):

void MainWindow::on_actionBlur_triggered()
{
    QGraphicsBlurEffect *a=new QGraphicsBlurEffect;
    a->setBlurHints(QGraphicsBlurEffect::QualityHint);
    a->boundingRectFor(ui->graphicsView->viewport()->rect());
    ui->graphicsView->setGraphicsEffect(a);
}

Can you spot the mistake or propose a different way fo doing this?

Answers


Panagiotis Sakkis February 2016

I've find a solution by calling the trigger for a second recursively.In numOfTriggers i save the times that i called it.

void Editor::on_actionBlur_triggered()
{
    if(numOfTriggers<2){
        QGraphicsBlurEffect *a=new QGraphicsBlurEffect;
        a->setBlurHints(QGraphicsBlurEffect::QualityHint);
        a->boundingRectFor(ui->graphicsView->viewport()->rect());
        ui->graphicsView->setGraphicsEffect(a);
        numOfTriggers++;
        on_actionBlur_triggered();
    }
    else{
        numOfTriggers=0;
    }
}


floppy12 February 2016

I have another idea : you should pass the QGraphicsView to your QGraphicsBlurEffect in constructor.

QGraphicsBlurEffect* a = new QGraphicsBlurEffect(ui->graphicsView);

Give a try with your mainWindow or "this" if not working.

Post Status

Asked in February 2016
Viewed 1,534 times
Voted 8
Answered 2 times

Search




Leave an answer