Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Animation: "A paint device can only be painted by one painter at a time."



  • Hello everyone,

    I am currently trying to develop a GUI for a desktop application. I am using QPropertyAnimation and QGraphicsOpacityEffect to create moving navigation bars, as well as moving buttons with fade in/out effects.

    I get spammed with warnings when I click the buttons to run the animations. This is my first time animating with Qt C++/XML so please bear with me! I am hoping that someone can point me in the right direction. If you notice anything else wrong with the code, please feel free to let me know!

    Video Link

    [Video](https://i.gyazo.com/ead46927480f02fa908b9efd0dcd615e.mp4)
    

    Specs:

    Desktop Qt 6.1.2 MinGW 64-bit - Qt Creator 5.0.1, based on Qt 5.15.2.
    

    Warnings:

    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    

    Implementation:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        // Page Setup
        ui->groupHome->setGeometry(0,330,1080,1590);
        ui->groupSearch->setGeometry(0,330,1080,1590);
        ui->groupSupply->setGeometry(0,330,1080,1590);
    
        // Fade Out
        QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
        ui->groupSearch->setGraphicsEffect(effectFadeOut);
        QPropertyAnimation *animationFadeOut = new QPropertyAnimation(effectFadeOut,"opacity");
        animationFadeOut->setDuration(1);
        animationFadeOut->setStartValue(1);
        animationFadeOut->setEndValue(0);
        animationFadeOut->setEasingCurve(QEasingCurve::OutBack);
        animationFadeOut->start()
        // / Fade Out
    
        // Fade Out
        QGraphicsOpacityEffect *effectFadeOut2 = new QGraphicsOpacityEffect(this);
        ui->groupSupply->setGraphicsEffect(effectFadeOut2);
        QPropertyAnimation *animationFadeOut2 = new QPropertyAnimation(effectFadeOut2,"opacity");
        animationFadeOut2->setDuration(1);
        animationFadeOut2->setStartValue(1);
        animationFadeOut2->setEndValue(0);
        animationFadeOut2->setEasingCurve(QEasingCurve::OutBack);
        animationFadeOut2->start();
        // / Fade Out
    
        ui->labelAnimationType->setGeometry(450,80,180,10);
        // / Page Setup
    }
    
    MainWindow::~MainWindow()
    {
        qDebug() << "MainWindow::~MainWindow: DECONSTRUCTING...";
        delete ui;
    }
    
    void MainWindow::on_buttonHome_clicked() // 0
    {
        qDebug() << "MainWindow::on_buttonHome_clicked: Clicked.";
    
        // Button Switch
        QPropertyAnimation *animation = new QPropertyAnimation(ui->labelNavAnimation, "geometry");
        animation->setDuration(300);
        animation->setStartValue(ui->labelNavAnimation->geometry());
        animation->setEndValue(QRect(472, 0, 136, 108));
        animation->start();
        // / Button Switch
    
        if(navigation == 1) // Search to Home
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->groupSearch->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeOut = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeOut->setDuration(300);
            animationFadeOut->setStartValue(1);
            animationFadeOut->setEndValue(0);
            animationFadeOut->setEasingCurve(QEasingCurve::OutBack);
            animationFadeOut->start();
            // / Fade Out
    
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupHome->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
            // / Fade In
        }
        else if(navigation == 2) // Supply to Home
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->groupSupply->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeOut = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeOut->setDuration(300);
            animationFadeOut->setStartValue(1);
            animationFadeOut->setEndValue(0);
            animationFadeOut->setEasingCurve(QEasingCurve::OutBack);
            animationFadeOut->start();
    
            connect(animationFadeOut,&QPropertyAnimation::finished,[=](){effectFadeOut->deleteLater(); ui->groupSupply->setVisible(0); });
            // / Fade Out
    
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupHome->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
    
            connect(animationFadeOut,&QPropertyAnimation::finished,[=](){effectFadeOut->deleteLater(); ui->groupHome->setVisible(1); });
            // / Fade In
        }
        navigation = 0;
    }
    
    void MainWindow::on_buttonSearch_clicked() // 1
    {
        qDebug() << "MainWindow::on_buttonSearch_clicked: Clicked.";
    
        // Button Switch
        QPropertyAnimation *animation = new QPropertyAnimation(ui->labelNavAnimation, "geometry");
        animation->setDuration(300);
        animation->setStartValue(ui->labelNavAnimation->geometry());
        animation->setEndValue(QRect(200, 0, 136, 108));
        animation->start();
        // / Button Switch
    
        if(navigation == 0) // Home to Search
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->groupHome->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeIn = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeIn->setDuration(300);
            animationFadeIn->setStartValue(1);
            animationFadeIn->setEndValue(0);
            animationFadeIn->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn->start();
            // / Fade Out
    
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupSearch->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
            // / Fade In
        }
        else if(navigation == 2) // Supply to Search
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->groupSupply->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeIn = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeIn->setDuration(300);
            animationFadeIn->setStartValue(1);
            animationFadeIn->setEndValue(0);
            animationFadeIn->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn->start();
            // / Fade Out
    
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupSearch->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
            // / Fade In
        }
    
        navigation = 1;
    }
    
    void MainWindow::on_buttonSupply_clicked() // 2
    {
        qDebug() << "MainWindow::on_buttonSupply_clicked: Clicked.";
    
        // Button Switch
        QPropertyAnimation *animation = new QPropertyAnimation(ui->labelNavAnimation, "geometry");
        animation->setDuration(300);
        animation->setStartValue(ui->labelNavAnimation->geometry());
        animation->setEndValue(QRect(750, 0, 136, 108));
        animation->start();
        // / Button Switch
    
        if(navigation == 0) // Home to Supply
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->groupHome->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeIn = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeIn->setDuration(300);
            animationFadeIn->setStartValue(1);
            animationFadeIn->setEndValue(0);
            animationFadeIn->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn->start();
    
            connect(animationFadeIn,&QPropertyAnimation::finished,[=](){effectFadeOut->deleteLater(); ui->groupHome->setVisible(0); });
            // / Fade Out
    
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupSupply->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
    
            connect(a,&QPropertyAnimation::finished,[=](){eff->deleteLater(); ui->groupSupply->setVisible(1); });
            // / Fade In
        }
        else if(navigation == 1) // Search to Supply
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->groupSearch->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeOut = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeOut->setDuration(300);
            animationFadeOut->setStartValue(1);
            animationFadeOut->setEndValue(0);
            animationFadeOut->setEasingCurve(QEasingCurve::OutBack);
            animationFadeOut->start();
            connect(animationFadeOut,&QPropertyAnimation::finished,[=](){effectFadeOut->deleteLater(); ui->groupSearch->setVisible(0);});
            // / Fade Out
    
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->groupSupply->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
            // / Fade In
        }
        navigation = 2;
    }
    
    void MainWindow::on_buttonHomeAll_clicked()
    {
        qDebug() << "MainWindow::on_buttonHomeAll_clicked: Clicked.";
    
        ui->buttonHomeAll-> setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:red; } ");
        ui->buttonHomeG->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:black; } ");
        ui->buttonHomeD->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:black; } ");
    
        // Filter Button Movement
        QPropertyAnimation *animation = new QPropertyAnimation(ui->labelAnimationType, "geometry");
        animation->setDuration(300);
        animation->setStartValue(ui->labelAnimationType->geometry());
        animation->setEndValue(QRect(450, 80, 180, 10));
        animation->start();
        // / Filter Button Movement
    
        if(filterType == 1) // G to All
        {
            // Fade In
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->buttonFuel7->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(300);
            a->setStartValue(0);
            a->setEndValue(1);
            a->setEasingCurve(QEasingCurve::InBack);
            a->start();
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *eff2 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel8->setGraphicsEffect(eff2);
            QPropertyAnimation *a2 = new QPropertyAnimation(eff2,"opacity");
            a2->setDuration(300);
            a2->setStartValue(0);
            a2->setEndValue(1);
            a2->setEasingCurve(QEasingCurve::InBack);
            a2->start();
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *eff3 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel9->setGraphicsEffect(eff3);
            QPropertyAnimation *a3 = new QPropertyAnimation(eff3,"opacity");
            a3->setDuration(300);
            a3->setStartValue(0);
            a3->setEndValue(1);
            a3->setEasingCurve(QEasingCurve::InBack);
            a3->start();
            // / Fade In
    
            // Button Movement
            QPropertyAnimation *animation2 = new QPropertyAnimation(ui->buttonFuel10, "geometry");
            animation2->setDuration(300);
            animation2->setStartValue(ui->buttonFuel10->geometry());
            animation2->setEndValue(QRect(80, 1240, 290, 290));
            animation2->start();
            // / Button Movement
        }
        else if(filterType == 2)
        {
            // Button Movement
            QPropertyAnimation *animation5 = new QPropertyAnimation(ui->buttonFuel7, "geometry");
            animation5->setDuration(300);
            animation5->setStartValue(ui->buttonFuel7->geometry());
            animation5->setEndValue(QRect(80, 930, 290, 290));
            animation5->start();
            // / Button Movement
    
            // Button Movement
            QPropertyAnimation *animation3 = new QPropertyAnimation(ui->buttonFuel8, "geometry");
            animation3->setDuration(300);
            animation3->setStartValue(ui->buttonFuel8->geometry());
            animation3->setEndValue(QRect(395, 930, 290, 290));
            animation3->start();
            // / Button Movement
    
            // Button Movement
            QPropertyAnimation *animation4 = new QPropertyAnimation(ui->buttonFuel9, "geometry");
            animation4->setDuration(300);
            animation4->setStartValue(ui->buttonFuel9->geometry());
            animation4->setEndValue(QRect(710, 930, 290, 290));
            animation4->start();
            // / Button Movement
    
    
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect1 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel1->setGraphicsEffect(fadeInEffect1);
            QPropertyAnimation *animationFaceIn = new QPropertyAnimation(fadeInEffect1,"opacity");
            animationFaceIn->setDuration(300);
            animationFaceIn->setStartValue(0);
            animationFaceIn->setEndValue(1);
            animationFaceIn->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn->start();
    
            connect(animationFaceIn,&QPropertyAnimation::finished,[=](){fadeInEffect1->deleteLater(); ui->buttonFuel1->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect2 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel2->setGraphicsEffect(fadeInEffect2);
            QPropertyAnimation *animationFaceIn2 = new QPropertyAnimation(fadeInEffect2,"opacity");
            animationFaceIn2->setDuration(300);
            animationFaceIn2->setStartValue(0);
            animationFaceIn2->setEndValue(1);
            animationFaceIn2->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn2->start();
    
            connect(animationFaceIn2,&QPropertyAnimation::finished,[=](){fadeInEffect2->deleteLater(); ui->buttonFuel2->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect3 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel3->setGraphicsEffect(fadeInEffect3);
            QPropertyAnimation *animationFaceIn3 = new QPropertyAnimation(fadeInEffect3,"opacity");
            animationFaceIn3->setDuration(300);
            animationFaceIn3->setStartValue(0);
            animationFaceIn3->setEndValue(1);
            animationFaceIn3->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn3->start();
    
            connect(animationFaceIn3,&QPropertyAnimation::finished,[=](){fadeInEffect3->deleteLater(); ui->buttonFuel3->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect4 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel4->setGraphicsEffect(fadeInEffect4);
            QPropertyAnimation *animationFaceIn4 = new QPropertyAnimation(fadeInEffect4,"opacity");
            animationFaceIn4->setDuration(300);
            animationFaceIn4->setStartValue(0);
            animationFaceIn4->setEndValue(1);
            animationFaceIn4->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn4->start();
    
            connect(animationFaceIn4,&QPropertyAnimation::finished,[=](){fadeInEffect4->deleteLater(); ui->buttonFuel4->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect5 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel5->setGraphicsEffect(fadeInEffect5);
            QPropertyAnimation *animationFaceIn5 = new QPropertyAnimation(fadeInEffect5,"opacity");
            animationFaceIn5->setDuration(300);
            animationFaceIn5->setStartValue(0);
            animationFaceIn5->setEndValue(1);
            animationFaceIn5->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn5->start();
    
            connect(animationFaceIn5,&QPropertyAnimation::finished,[=](){fadeInEffect5->deleteLater(); ui->buttonFuel5->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect6 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel6->setGraphicsEffect(fadeInEffect6);
            QPropertyAnimation *animationFaceIn6 = new QPropertyAnimation(fadeInEffect6,"opacity");
            animationFaceIn6->setDuration(300);
            animationFaceIn6->setStartValue(0);
            animationFaceIn6->setEndValue(1);
            animationFaceIn6->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn6->start();
    
            connect(animationFaceIn6,&QPropertyAnimation::finished,[=](){fadeInEffect6->deleteLater(); ui->buttonFuel6->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect7 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel10->setGraphicsEffect(fadeInEffect7);
            QPropertyAnimation *animationFaceIn7 = new QPropertyAnimation(fadeInEffect7,"opacity");
            animationFaceIn7->setDuration(300);
            animationFaceIn7->setStartValue(0);
            animationFaceIn7->setEndValue(1);
            animationFaceIn7->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn7->start();
    
            connect(animationFaceIn7,&QPropertyAnimation::finished,[=](){fadeInEffect7->deleteLater(); ui->buttonFuel10->setVisible(1); });
            // / Fade In
    
        }
    
        filterType = 0;
    }
    
    void MainWindow::on_buttonHomeG_clicked()
    {
        qDebug() << "MainWindow::on_buttonHomeG_clicked: Clicked.";
    
        ui->buttonHomeAll->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:black; } ");
        ui->buttonHomeG->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:red; } ");
        ui->buttonHomeD->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:black; } ");
    
        // Filter Button Movement
        QPropertyAnimation *animation = new QPropertyAnimation(ui->labelAnimationType, "geometry");
        animation->setDuration(300);
        animation->setStartValue(ui->labelAnimationType->geometry());
        animation->setEndValue(QRect(150, 80, 180, 10));
        animation->start();
        // / Filter Button Movement
    
        if(filterType == 0) // All to G
        {
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->buttonFuel7->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeIn = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeIn->setDuration(300);
            animationFadeIn->setStartValue(1);
            animationFadeIn->setEndValue(0);
            animationFadeIn->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn->start();
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut2 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel8->setGraphicsEffect(effectFadeOut2);
            QPropertyAnimation *animationFadeIn2 = new QPropertyAnimation(effectFadeOut2,"opacity");
            animationFadeIn2->setDuration(300);
            animationFadeIn2->setStartValue(1);
            animationFadeIn2->setEndValue(0);
            animationFadeIn2->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn2->start();
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut3 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel9->setGraphicsEffect(effectFadeOut3);
            QPropertyAnimation *animationFadeIn3 = new QPropertyAnimation(effectFadeOut3,"opacity");
            animationFadeIn3->setDuration(300);
            animationFadeIn3->setStartValue(1);
            animationFadeIn3->setEndValue(0);
            animationFadeIn3->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn3->start();
            // / Fade Out
    
            // Button Movement
            QPropertyAnimation *animation2 = new QPropertyAnimation(ui->buttonFuel10, "geometry");
            animation2->setDuration(300);
            animation2->setStartValue(ui->buttonFuel10->geometry());
            animation2->setEndValue(QRect(80, 930, 290, 290));
            animation2->start();
            // / Button Movement
        }
    
        filterType = 1;
    }
    
    void MainWindow::on_buttonHomeD_clicked()
    {
        qDebug() << "MainWindow::on_buttonHomeD_clicked: Clicked.";
    
        ui->buttonHomeAll->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:black; } ");
        ui->buttonHomeG->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:black; } ");
        ui->buttonHomeD->setStyleSheet("QPushButton { background-color:white;  border:none; font-size:32px; border-bottom: 2px solid rgb(217,217,217); color:red; } ");
    
        // Filter Button Movement
        QPropertyAnimation *animation = new QPropertyAnimation(ui->labelAnimationType, "geometry");
        animation->setDuration(300);
        animation->setStartValue(ui->labelAnimationType->geometry());
        animation->setEndValue(QRect(750, 80, 180, 10));
        animation->start();
        // / Filter Button Movement
    
        if(filterType == 0) 
        {
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut = new QGraphicsOpacityEffect(this);
            ui->buttonFuel1->setGraphicsEffect(effectFadeOut);
            QPropertyAnimation *animationFadeOut = new QPropertyAnimation(effectFadeOut,"opacity");
            animationFadeOut->setDuration(300);
            animationFadeOut->setStartValue(1);
            animationFadeOut->setEndValue(0);
            animationFadeOut->setEasingCurve(QEasingCurve::OutBack);
            animationFadeOut->start();
    
            connect(animationFadeOut,&QPropertyAnimation::finished,[=](){effectFadeOut->deleteLater(); ui->buttonFuel1->setVisible(0); });
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut2 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel2->setGraphicsEffect(effectFadeOut2);
            QPropertyAnimation *animationFadeIn2 = new QPropertyAnimation(effectFadeOut2,"opacity");
            animationFadeIn2->setDuration(300);
            animationFadeIn2->setStartValue(1);
            animationFadeIn2->setEndValue(0);
            animationFadeIn2->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn2->start();
    
            connect(animationFadeIn2,&QPropertyAnimation::finished,[=](){effectFadeOut2->deleteLater(); ui->buttonFuel1->setVisible(0); });
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut3 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel3->setGraphicsEffect(effectFadeOut3);
            QPropertyAnimation *animationFadeIn3 = new QPropertyAnimation(effectFadeOut3,"opacity");
            animationFadeIn3->setDuration(300);
            animationFadeIn3->setStartValue(1);
            animationFadeIn3->setEndValue(0);
            animationFadeIn3->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn3->start();
    
            connect(animationFadeIn3,&QPropertyAnimation::finished,[=](){effectFadeOut3->deleteLater(); ui->buttonFuel3->setVisible(0); });
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut4 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel4->setGraphicsEffect(effectFadeOut4);
            QPropertyAnimation *animationFadeIn4 = new QPropertyAnimation(effectFadeOut4,"opacity");
            animationFadeIn4->setDuration(300);
            animationFadeIn4->setStartValue(1);
            animationFadeIn4->setEndValue(0);
            animationFadeIn4->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn4->start();
    
            connect(animationFadeIn4,&QPropertyAnimation::finished,[=](){effectFadeOut4->deleteLater(); ui->buttonFuel4->setVisible(0); });
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut5 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel5->setGraphicsEffect(effectFadeOut5);
            QPropertyAnimation *animationFadeIn5 = new QPropertyAnimation(effectFadeOut5,"opacity");
            animationFadeIn5->setDuration(300);
            animationFadeIn5->setStartValue(1);
            animationFadeIn5->setEndValue(0);
            animationFadeIn5->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn5->start();
    
            connect(animationFadeIn5,&QPropertyAnimation::finished,[=](){effectFadeOut5->deleteLater(); ui->buttonFuel5->setVisible(0); });
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut6 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel6->setGraphicsEffect(effectFadeOut6);
            QPropertyAnimation *animationFadeIn6 = new QPropertyAnimation(effectFadeOut6,"opacity");
            animationFadeIn6->setDuration(300);
            animationFadeIn6->setStartValue(1);
            animationFadeIn6->setEndValue(0);
            animationFadeIn6->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn6->start();
    
            connect(animationFadeIn6,&QPropertyAnimation::finished,[=](){effectFadeOut6->deleteLater(); ui->buttonFuel6->setVisible(0); });
            // / Fade Out
    
            // Fade Out
            QGraphicsOpacityEffect *effectFadeOut7 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel10->setGraphicsEffect(effectFadeOut7);
            QPropertyAnimation *animationFadeIn7 = new QPropertyAnimation(effectFadeOut7,"opacity");
            animationFadeIn7->setDuration(300);
            animationFadeIn7->setStartValue(1);
            animationFadeIn7->setEndValue(0);
            animationFadeIn7->setEasingCurve(QEasingCurve::OutBack);
            animationFadeIn7->start();
    
            connect(animationFadeIn7,&QPropertyAnimation::finished,[=](){effectFadeOut7->deleteLater(); ui->buttonFuel10->setVisible(0); });
            // / Fade Out
    
            // Button Movement
            QPropertyAnimation *animation2 = new QPropertyAnimation(ui->buttonFuel7, "geometry");
            animation2->setDuration(300);
            animation2->setStartValue(ui->buttonFuel7->geometry());
            animation2->setEndValue(QRect(80, 310, 290, 290));
            animation2->start();
            // / Button Movement
    
            // Button Movement
            QPropertyAnimation *animation3 = new QPropertyAnimation(ui->buttonFuel8, "geometry");
            animation3->setDuration(300);
            animation3->setStartValue(ui->buttonFuel8->geometry());
            animation3->setEndValue(QRect(395, 310, 290, 290));
            animation3->start();
            // / Button Movement
    
            // Button Movement
            QPropertyAnimation *animation4 = new QPropertyAnimation(ui->buttonFuel9, "geometry");
            animation4->setDuration(300);
            animation4->setStartValue(ui->buttonFuel9->geometry());
            animation4->setEndValue(QRect(710, 310, 290, 290));
            animation4->start();
            // / Button Movement
        }
        filterType = 2;
    }
    
    

    Thanks in advance,
    Ryan.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since you do not keep the animation, I would use the parameter of the start method to let it be destroyed appropriately. See if that improves the situation.



  • @SGaist Thanks for the response!

    I replaced all the start() functions with start(QAbstractAnimation::DeleteWhenStopped), but I'm still getting the same warnings whenever I click the navigation buttons.

    Is it a requirement to use the save/restore functions for this type of animation, as I get the odd message about unbalanced save/restore? This is the qDebug+Warning output from a single button click:

    MainWindow::on_buttonHomeAll_clicked: D to All.
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::begin: A paint device can only be painted by one painter at a time.
    QPainter::translate: Painter not active
    QPainter::worldTransform: Painter not active
    QWidgetEffectSourcePrivate::pixmap: Painter not active
    QPainter::save: Painter not active
    QPainter::setOpacity: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::restore: Unbalanced save/restore
    

    Updated implementation of same button click

    qDebug() << "MainWindow::on_buttonHomeAll_clicked: D to All.";
            // Button Movement
            QPropertyAnimation *animation5 = new QPropertyAnimation(ui->buttonFuel7, "geometry");
            animation5->setDuration(300);
            animation5->setStartValue(ui->buttonFuel7->geometry());
            animation5->setEndValue(QRect(80, 930, 290, 290));
            animation5->start(QAbstractAnimation::DeleteWhenStopped);
            // / Button Movement
    
            // Button Movement
            QPropertyAnimation *animation3 = new QPropertyAnimation(ui->buttonFuel8, "geometry");
            animation3->setDuration(300);
            animation3->setStartValue(ui->buttonFuel8->geometry());
            animation3->setEndValue(QRect(395, 930, 290, 290));
            animation3->start(QAbstractAnimation::DeleteWhenStopped);
            // / Button Movement
    
            // Button Movement
            QPropertyAnimation *animation4 = new QPropertyAnimation(ui->buttonFuel9, "geometry");
            animation4->setDuration(300);
            animation4->setStartValue(ui->buttonFuel9->geometry());
            animation4->setEndValue(QRect(710, 930, 290, 290));
            animation4->start(QAbstractAnimation::DeleteWhenStopped);
            // / Button Movement
    
    
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect1 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel1->setGraphicsEffect(fadeInEffect1);
            QPropertyAnimation *animationFaceIn = new QPropertyAnimation(fadeInEffect1,"opacity");
            animationFaceIn->setDuration(300);
            animationFaceIn->setStartValue(0);
            animationFaceIn->setEndValue(1);
            animationFaceIn->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn,&QPropertyAnimation::finished,[=](){fadeInEffect1->deleteLater(); ui->buttonFuel1->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect2 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel2->setGraphicsEffect(fadeInEffect2);
            QPropertyAnimation *animationFaceIn2 = new QPropertyAnimation(fadeInEffect2,"opacity");
            animationFaceIn2->setDuration(300);
            animationFaceIn2->setStartValue(0);
            animationFaceIn2->setEndValue(1);
            animationFaceIn2->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn2->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn2,&QPropertyAnimation::finished,[=](){fadeInEffect2->deleteLater(); ui->buttonFuel2->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect3 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel3->setGraphicsEffect(fadeInEffect3);
            QPropertyAnimation *animationFaceIn3 = new QPropertyAnimation(fadeInEffect3,"opacity");
            animationFaceIn3->setDuration(300);
            animationFaceIn3->setStartValue(0);
            animationFaceIn3->setEndValue(1);
            animationFaceIn3->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn3->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn3,&QPropertyAnimation::finished,[=](){fadeInEffect3->deleteLater(); ui->buttonFuel3->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect4 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel4->setGraphicsEffect(fadeInEffect4);
            QPropertyAnimation *animationFaceIn4 = new QPropertyAnimation(fadeInEffect4,"opacity");
            animationFaceIn4->setDuration(300);
            animationFaceIn4->setStartValue(0);
            animationFaceIn4->setEndValue(1);
            animationFaceIn4->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn4->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn4,&QPropertyAnimation::finished,[=](){fadeInEffect4->deleteLater(); ui->buttonFuel4->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect5 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel5->setGraphicsEffect(fadeInEffect5);
            QPropertyAnimation *animationFaceIn5 = new QPropertyAnimation(fadeInEffect5,"opacity");
            animationFaceIn5->setDuration(300);
            animationFaceIn5->setStartValue(0);
            animationFaceIn5->setEndValue(1);
            animationFaceIn5->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn5->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn5,&QPropertyAnimation::finished,[=](){fadeInEffect5->deleteLater(); ui->buttonFuel5->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect6 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel6->setGraphicsEffect(fadeInEffect6);
            QPropertyAnimation *animationFaceIn6 = new QPropertyAnimation(fadeInEffect6,"opacity");
            animationFaceIn6->setDuration(300);
            animationFaceIn6->setStartValue(0);
            animationFaceIn6->setEndValue(1);
            animationFaceIn6->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn6->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn6,&QPropertyAnimation::finished,[=](){fadeInEffect6->deleteLater(); ui->buttonFuel6->setVisible(1); });
            // / Fade In
    
            // Fade In
            QGraphicsOpacityEffect *fadeInEffect7 = new QGraphicsOpacityEffect(this);
            ui->buttonFuel10->setGraphicsEffect(fadeInEffect7);
            QPropertyAnimation *animationFaceIn7 = new QPropertyAnimation(fadeInEffect7,"opacity");
            animationFaceIn7->setDuration(300);
            animationFaceIn7->setStartValue(0);
            animationFaceIn7->setEndValue(1);
            animationFaceIn7->setEasingCurve(QEasingCurve::InBack);
            animationFaceIn7->start(QAbstractAnimation::DeleteWhenStopped);
    
            connect(animationFaceIn7,&QPropertyAnimation::finished,[=](){fadeInEffect7->deleteLater(); ui->buttonFuel10->setVisible(1); });
            // / Fade In
    

  • Lifetime Qt Champion

    Can you provide a minimal compilable example that reproduces this ?

    Did you try with 6.2 since was released yesterday ?



  • @SGaist

    Thanks for taking the time! I have tried with the following compilers, all issuing the same warnings;

    Qt 6.1.2 MinGW & MSVC 2019 64-bit
    Qt 5.12.11 MinGW 64-bit & 32-bit
    Qt 5.12.11 MSVC 2017 64-bit
    Edit: Qt 6.2 MingGW 64-bit

    I have cleaned up the code and made a GitHub Gist as I kept hitting the character limit for the forums. If you would like it in another format, please feel free to let me know.

    Project Link.


  • Lifetime Qt Champion

    Works for me on macOS with Qt 5.15.2.



  • @SGaist

    Very strange! It is worth mentioning that I only get the warnings when I click one of the main navigation bars, then one of the filters.

    For example; click Supply, then Home (no warnings), then Filter 2 (warnings spam).



  • If anyone else is able to trigger the warnings by clicking Supply, Home, then the Filters, please let me know what versions you're running!

    Thanks,
    Ryan



  • I ended up requesting support with Qt Enterprise and they gave instructions on how to fix it.

    For anyone else having this issue, I had to setGraphicsEffect to nullptr after the animation has finished: "ui->buttonItem10->setGraphicsEffect(nullptr);".

    connect(animationFadeIn7,&QPropertyAnimation::finished,[=](){effectFadeOut7->deleteLater(); ui->buttonItem10->setVisible(0); ui->buttonItem10->setGraphicsEffect(nullptr); });
    

  • Lifetime Qt Champion

    Thanks for the feedback and solution !


Log in to reply