|  | Home

# QtAnimation Class Reference
[QtCore module]

The QtAnimation class provides an abstract base class for animations. More...

     #include <QtAnimation>

This class is under development and is subject to change.

Inherits QtAbstractAnimation.

Inherited by QtPropertyAnimation.

- List of all members, including inherited members

### Public Types

- typedef Interpolator
- typedef KeyFrame
- typedef KeyFrames

### Properties

currentValue : const QVariant duration : int easingCurve : QtEasingCurve | endValue : QVariant startValue : QVariant

- 6 properties inherited from QtAbstractAnimation
- 1 property inherited from QObject

### Public Functions

- QtAnimation ( QObject * parent = 0 )
- QVariant currentValue () const
- virtual int duration () const
- QtEasingCurve easingCurve () const
- QVariant endValue () const
- KeyFrames keyFrames () const
- void setDuration ( int msecs )
- void setEasingCurve ( const QtEasingCurve & easing )
- void setEndValue ( const QVariant & value )
- void setKeyFrames ( const KeyFrames & keyFrames )
- void setStartValue ( const QVariant & value )
- void setValueAt ( qreal step, const QVariant & value )
- QVariant startValue () const
- QVariant valueAt ( qreal step ) const

- 10 public functions inherited from QtAbstractAnimation
- 29 public functions inherited from QObject

### Signals

- void durationChanged ( int duration )
- void valueChanged ( const QVariant & value )

- 5 signals inherited from QtAbstractAnimation
- 1 signal inherited from QObject

### Protected Functions

- QVariant defaultStartValue () const
- virtual QVariant interpolated ( const QVariant & from, const QVariant & to, qreal progress ) const
- void setDefaultStartValue ( const QVariant & value )
- virtual void updateCurrentValue ( const QVariant & value ) = 0

- 3 protected functions inherited from QtAbstractAnimation
- 7 protected functions inherited from QObject

### Related Non-Members

- void qRegisterAnimationInterpolator ( QtAnimation::Interpolator func )

### Additional Inherited Members

- 5 public slots inherited from QtAbstractAnimation
- 1 public slot inherited from QObject
- 1 public type inherited from QObject
- 4 static public members inherited from QObject
- 2 protected variables inherited from QObject

## Detailed Description

The QtAnimation class provides an abstract base class for animations.

This class is part of {The Animation Framework}. It serves as a base class for property and item animations, with functions for shared functionality.

If you want to create an animation, you should look at QtPropertyAnimation instead.

You can then set start and end values for the property by calling setStartValue() and setEndValue(), and finally call start() to start the animation. When control goes back to the event loop, QtAnimation will interpolate the property of the target object and emit the valueChanged signal. To react to a change in the current value you have to reimplement the updateCurrentValue virtual method.

There are two ways to affect how QtAnimation interpolates the values. You can set an easing curve by calling setEasingCurve(), and configure the duration by calling setDuration(). You can change how the QVariants are interpolated by creating a subclass of QtAnimation, and reimplementing the virtual interpolated() function.

See also QtPropertyAnimation and The Animation Framework.

## Member Type Documentation

### typedef QtAnimation::Interpolator

This is a typedef for a pointer to a function with the following signature:

     QVariant myInterpolator(const QVariant &from, const QVariant &to, qreal progress);

### typedef QtAnimation::KeyFrame

This is a typedef for QPair<qreal, QVariant>.

### typedef QtAnimation::KeyFrames

This is a typedef for QVector<KeyFrame>

## Property Documentation

### currentValue : const QVariant

This property holds the current value of the animation.

This property describes the current value; an interpolation between the start value and the end value, using the current time for progress.

QtAnimation calls the virtual updateCurrentValue() function when the current value changes. This is particularily useful for subclasses that need to track updates.

Access functions:

- QVariant currentValue () const

See also startValue and endValue.

### duration : int

This property holds the duration of the animation.

This property describes the duration of the animation. The default duration is 250 milliseconds.

Access functions:

- virtual int duration () const
- void setDuration ( int msecs )

See also QtAbstractAnimation::duration().

### easingCurve : QtEasingCurve

This property holds the easing curve of the animation.

This property defines the easing curve of the animation. By default, a linear easing curve is used, resulting in linear interpolation of the end property. For many animations, it's useful to try different easing curves, including QtEasingCurve::InCirc, which provides a circular entry curve, and QtEasingCurve::InOutElastic, which provides an elastic effect on the values of the interpolated property.

The easing curve is used with the interpolator, the interpolated() virtual function, the animation's duration, and loopCount, to control how the current value changes as the animation progresses.

Access functions:

- QtEasingCurve easingCurve () const
- void setEasingCurve ( const QtEasingCurve & easing )

### endValue : QVariant

This property holds the end value of the animation.

This property describes the end value of the animation.

Access functions:

- QVariant endValue () const
- void setEndValue ( const QVariant & value )

See also startValue.

### startValue : QVariant

This property holds the optional start value of the animation.

This property describes the optional start value of the animation. If omitted, or if a null QVariant is assigned as the start value, the animation will use the current position of the end when the animation is started.

Access functions:

- QVariant startValue () const
- void setStartValue ( const QVariant & value )

See also endValue.

## Member Function Documentation

### QtAnimation::QtAnimation ( QObject * parent = 0 )

Construct a QtAnimation object. parent is passed to QtAbstractAnimation's constructor.

### QVariant QtAnimation::defaultStartValue () const `[protected]`

gets the default start value that will be used in case no start value is explicitly set.

See also setDefaultStartValue() and startValue.

### void QtAnimation::durationChanged ( int duration ) `[signal]`

QtAnimation emits this signal whenever the duration of the animation changes.

See also setDuration() and duration().

### QVariant QtAnimation::interpolated ( const QVariant & from, const QVariant & to, qreal progress ) const `[virtual protected]`

This virtual function returns the linear interpolation between variants from and to, at progress, usually a value between 0 and 1. You can reimplement this function in a subclass of QtAnimation to provide your own interpolation algorithm. Note that in order for the interpolation to work with a QtEasingCurve that return a value smaller than 0 or larger than 1 (such as QtEasingCurve::InBack) you should make sure that it can extrapolate. If the semantic of the datatype does not allow extrapolation this function should handle that gracefully.

See also QtEasingCurve.

### KeyFrames QtAnimation::keyFrames () const

Returns the key frames of this animation.

See also setKeyFrames() and valueAt().

### void QtAnimation::setDefaultStartValue ( const QVariant & value ) `[protected]`

Sets the default start value to value that will be used by the animation in case it has no defined start value. This is used by subclasses of QtAnimation to define a default behaviour and allow to create an animation with simply a target value.

See also defaultStartValue() and startValue.

### void QtAnimation::setKeyFrames ( const KeyFrames & keyFrames )

Replaces the current set of key frames with the given keyFrames. the step of the key frames must be in the range 0 to 1.

See also keyFrames() and valueAt().

### void QtAnimation::setValueAt ( qreal step, const QVariant & value )

Creates a key frame at the given step with the given value. The given step must be in the range 0 to 1.

See also setKeyFrames() and valueAt().

### void QtAnimation::updateCurrentValue ( const QVariant & value ) `[pure virtual protected]`

This pure virtual function is called when the animated value is changed. value is the new value.

### QVariant QtAnimation::valueAt ( qreal step ) const

Returns the key frame value for the given step. The given step must be in the range 0 to 1. If there is no keyframe for step, it returns an invalid QVariant.

See also keyFrames() and setValueAt().

### void QtAnimation::valueChanged ( const QVariant & value ) `[signal]`

QtAnimation emits this signal whenever the current value changes.

See also currentValue, startValue, and endValue.

## Related Non-Members

### void qRegisterAnimationInterpolator ( QtAnimation::Interpolator func ) `[static]`

Registers a custom interpolator func for the template type `T`. The interpolator has to be registered before the animation is constructed. To unregister (and use the default interpolator) set func to 0.

Note: This function is thread-safe.