0

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?

2 Answers2

0

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;
    }
}
0

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.

floppy12
  • 1,045
  • 6
  • 12