Sequential animations seem to start early
I have an animation that changes the size of a widget. Because it is a widget contained in a dockwidget, I grow it by changing the minimumSize then reset its minimumSize to 0,0. I use a QSequentialAnimationGroup for these two changes, however when the duration of the second animation is short, the widget does not grow all the way to specified size. It appears that the second animation starts before the first one finishes. Here is the code:
@ QSequentialAnimationGroup* seqGroup = new QSequentialAnimationGroup();
QPropertyAnimation* anim = new QPropertyAnimation(widget(), "minimumHeight"); anim->setEndValue(height); anim->setDuration(animationDuration); seqGroup->addAnimation(anim); QPropertyAnimation* defixMaxSize = new QPropertyAnimation(widget(), "maximumSize"); defixMaxSize->setEndValue(QSize(16777215,16777215)); defixMaxSize->setDuration(1); seqGroup->addAnimation(defixMaxSize); QPropertyAnimation* defixMinSize = new QPropertyAnimation(widget(), "minimumSize"); defixMinSize->setEndValue(QSize(0,0)); defixMinSize->setDuration(1); seqGroup->addAnimation(defixMinSize); seqGroup->start(QAbstractAnimation::DeleteWhenStopped);@
When the duration of the second two animations are 1, the widget does not grow all the way to "height", if the duration is changed to 10, they seem much more likely to. Can anybody clue me into why this is happening?
I'm not sure, but a duration value of 1 means 1ms. Since the second animation start immediately after the first one finishes, maybe you're just not noticing that it grew completely. You could also try to "add a pause":http://doc.qt.nokia.com/4.7/qsequentialanimationgroup.html#addPause .
A pause of 1 ms did not help. Thanks for the suggestion. I realize that 1 ms is short, but the widget does not reach the end value of the first animation when the whole animation sequence finishes.
Just as a test, have you tried using longer durations (say 250ms each) for each of the animations? Starting with larger numbers then reducing the duration down may give some insight to the operation of the sequential animation and how its interacting with the individual animations. There may be a floor value where things don't behave quite right because of the resolution of the system timers.