August 3, 2011

TheClassic TheClassic
Lab Rat
5 posts

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:

  1.     QSequentialAnimationGroup* seqGroup = new QSequentialAnimationGroup();
  3.     QPropertyAnimation* anim = new QPropertyAnimation(widget(), "minimumHeight");
  4.     anim->setEndValue(height);
  5.     anim->setDuration(animationDuration);
  6.     seqGroup->addAnimation(anim);
  8.     QPropertyAnimation* defixMaxSize = new QPropertyAnimation(widget(), "maximumSize");
  9.     defixMaxSize->setEndValue(QSize(16777215,16777215));
  10.     defixMaxSize->setDuration(1);
  11.     seqGroup->addAnimation(defixMaxSize);
  13.     QPropertyAnimation* defixMinSize = new QPropertyAnimation(widget(), "minimumSize");
  14.     defixMinSize->setEndValue(QSize(0,0));
  15.     defixMinSize->setDuration(1);
  16.     seqGroup->addAnimation(defixMinSize);
  18.     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?

3 replies

August 4, 2011

loladiro loladiro
Lab Rat
594 posts

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 [] .

August 4, 2011

TheClassic TheClassic
Lab Rat
5 posts

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.

August 4, 2011

mlong mlong
Robot Herder
1537 posts

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.


Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

  ‹‹ Password transformation for crypto app      Licencing my App ››

You must log in to post a reply. Not a member yet? Register here!