Panagiotis Sakkis
Panagiotis Sakkis

Reputation: 150

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?

Upvotes: 0

Views: 589

Answers (2)

floppy12
floppy12

Reputation: 1053

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.

Upvotes: 0

Panagiotis Sakkis
Panagiotis Sakkis

Reputation: 150

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

Upvotes: 0

Related Questions