Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QPropertyAnimation code not workable
houmingc last edited by Chris Kawa
Newbie in QPropertyAnimation, trying to make code workable.
Please kindly assist.
code below shows nothing in mainwindow
ui->setupUi(this); QPushButton button("Animated Button"); button.show(); QPropertyAnimation animation(&button,"geometry"); animation.setDuration(5000); animation.setKeyValueAt(0,QRect(0,0,100,30)); animation.setKeyValueAt(0.8,QRect(250,250,100,30)); animation.setKeyValueAt(1,QRect(0,0,100,300)); animation.start();
code below error is:
QPropertyAnimation::updateState (windowOpacity): Changing state of an animation without target
QPropertyAnimation* animation = new QPropertyAnimation(this->parent(),"windowOpacity"); animation->setDuration(5000); animation->setStartValue(0.0); animation->setEndValue(1.0); animation->setEasingCurve(QEasingCurve::OutCubic); animation->start();
code below error is:
QPropertyAnimation::updateState (geometry, QPushButton, ): starting an animation without end value
ui->setupUi(this); QPushButton* bonnie = new QPushButton("Bonnie"); bonnie->show(); QPushButton* clyde = new QPushButton("clyde"); clyde->show(); QPropertyAnimation* anim1 = new QPropertyAnimation(bonnie, "geometry"); QPropertyAnimation* anim2 = new QPropertyAnimation(clyde,"geometry"); QParallelAnimationGroup* group = new QParallelAnimationGroup; group->addAnimation(anim1); group->addAnimation(anim2); group->start();
The first one: both button and animation are local stack variables and get destroyed at the end of the function, before anything starts to animate. Don't do that.
The second one: if this points to a top level widget then its parent is most probably null. You can't animate a property of non-existing object. Make sure the first parameter points to a valid object. Also make sure you either delete the animation object somewhere or give it a parent (3rd parameter) or else you're leaking memory.
Third one: you created two animations without any values i.e. it doesn't know how to animate the "geometry" property. Before you start the group add to your animations some duration, start and end values like in your previous examples. Also, again, make sure you delete the animations and the group or give them a parent or you're leaking memory.
p.s. This forum no longer uses @ for code blocks. To properly format code just indent it either 4 spaces or a tab. I edited your post to fix this.