Qt Animation: "A paint device can only be painted by one painter at a time."
-
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.
-
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/restoreUpdated 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 -
Can you provide a minimal compilable example that reproduces this ?
Did you try with 6.2 since was released yesterday ?
-
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-bitI 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.
-
Works for me on macOS with Qt 5.15.2.
-
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); }); -
Thanks for the feedback and solution !
-
It's nice to find out after a few years. My understanding of this error is that qt does not allow qgraphicseffect in parent-child controls to work at the same time. Therefore, a good practice is to turn qgraphicseffect on when you need to use it, using effect->setEnabled(ture), and turn it off when you don't need it.
In addition, because my English is not good, the above content is translated from the translation software. Please forgive me.