How it works...

Since we are using an animation group now, we no longer call the start() function from the individual animation. Instead, we will be calling the start() function from the animation group we just created. If you compile and run the example now, you will see all three buttons being played at the same time. This is because we are using the parallel animation group. You can replace it with a sequential animation group and run the example again:

QSequentialAnimationGroup *group = new QSequentialAnimationGroup;

This time, only a single button will play its animation at a time, while the other buttons will wait patiently for their turn to come. The priority is set based on which animation is added to the animation group first. You can change the animation sequence by simply rearranging the sequence of an animation that's being added to the group. For example, if we want button 3 to start the animation first, followed by button 2, and then button 1, the code will look like this:

group->addAnimation(animation3);
group->addAnimation(animation2);
group->addAnimation(animation1);

Since property animations and animation groups are both inherited from the QAbstractAnimator class, it means that you can also add an animation group to another animation group to form a more complex, nested animation group.