|  | Home

# The Animation Framework

The Animation Framework lets you define, run and control animations, states and transitions. The foundation classes QtAnimation and QtAnimationGroup are used to scoreboard both simple and complex animations. A simple animation might change a widget's geometry from one rectangle to another, over the course of 2 seconds, using a linear easing curve. You can group animations by adding them to animation groups (QtSequentialAnimationGroup or QtParallelAnimationGroup). In addition to this, The State Machine Framework lets you define and run state machines, and associate animations to the state transitions. The Animation Framework classes help maintain the necessary bookkeeping in order to provide animated forms and scenes.

- The Animation Architecture

- The animation classes
- The state machine classes

- Third party copyright notice

### The Animation Architecture

The Animation Framework foundation consists of the base class QtAbstractAnimation, and its two subclasses QtAnimation and QtAnimationGroup. In addition QtState lets you group special properties and values for QObjects in a defined state which can be entered and exited.

#### The animation classes

The abstract class QtAbstractAnimation provides an interface for getting notifications of time changes, so that it can perform the necessary updates it needs in order to keep something animated. A subclass of QtAbstractAnimation will get those notifications by reimplementing the pure virtual function QtAbstractAnimation::updateCurrentTime(). This usually means that the animation should update some property of the item it is set to animate.

The subclass QtPropertyAnimation is an example of this. A QtPropertyAnimation is an animation class that can animate properties. This means it can animate any QObject-based properties, but it is not capable of animating a QGraphicsItem. Thus, in order to set up a QtPropertyAnimation the minimum you need to specify is the object of the property you want to animate, the property itself, and the value the animation should end up at. In addition to that you can specify the startValue, duration and easing curve. If you want to animate a value through a list of intermediate values, you can specify those with key frames by using QtAnimation::setValueAt(). You can also change the direction of an animation by calling setDirection().

The QtEasingCurve is useful if you want to control the speed of an animation without changing the path of the interpolation. They allow transitions from one value to another to appear more natural than a simple constant speed would allow. For instance, using an easing curve of EaseInOut will make the movement accelerate from halt at the start, then decelarate towards the end until it halts. The speed can also be negative. You can for instance have a bounce effect by using an easing curve of BounceOut. This will let the movement slowly accelerate until it hits its target value, then it will bounce several times. When the bounce is lost it will be at the target value.

The subclasses of QtAnimationGroup (QtSequentialAnimationGroup and QtParallelAnimationGroup) are containers for other animations so they can be animated either in sequence or parallel. The QtAnimationGroup is an example of an animation that does not animate properties, but it gets notified of time changes periodically. This enables it to forward those time changes to its contained animations, making sure they are either animated in sequence or parallel.

#### The state machine classes

The state machine is a convenient way of setting up a UI form that has several logical states. QtAnimationState allows you to add animations to a state transition.

There is also QtAbstractStateGroup::addAnimatedTransition() that allows you to associate an animation to a state transition. This will create the QtAnimationState for you, and insert it into the state machine.

### Third party copyright notice

The QtEasingCurve class contains third party code with this copyright notice.