QVariantAnimation Class

The QVariantAnimation class provides a base class for animations. More...

Header: #include <QVariantAnimation>
qmake: QT += core
Since: Qt 4.6
Inherits: QAbstractAnimation
Inherited By:

QPropertyAnimation

This class was introduced in Qt 4.6.

Public Types

typedef KeyValue
typedef KeyValues

Properties

Public Functions

QVariant currentValue() const
QEasingCurve easingCurve() const
QVariant endValue() const
void setDuration(int msecs)
void setEasingCurve(const QEasingCurve &easing)
void setEndValue(const QVariant &value)
void setStartValue(const QVariant &value)
QVariant startValue() const

Reimplemented Public Functions

virtual int duration() const override

Signals

void valueChanged(const QVariant &value)

Detailed Description

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

The class performs interpolation over QVariants, but leaves using the interpolated values to its subclasses. Currently, Qt provides QPropertyAnimation, which animates Qt properties. See the QPropertyAnimation class description if you wish to animate such properties.

You can then set start and end values for the property by calling setStartValue() and setEndValue(), and finally call start() to start the animation. QVariantAnimation will interpolate the property of the target object and emit valueChanged(). To react to a change in the current value you have to reimplement the updateCurrentValue() virtual function or connect to said signal.

It is also possible to set values at specified steps situated between the start and end value. The interpolation will then touch these points at the specified steps. Note that the start and end values are defined as the key values at 0.0 and 1.0.

There are two ways to affect how QVariantAnimation 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 QVariantAnimation, and reimplementing the virtual interpolated() function.

Subclassing QVariantAnimation can be an alternative if you have QVariants that you do not wish to declare as Qt properties. Note, however, that you in most cases will be better off declaring your QVariant as a property.

Not all QVariant types are supported. Below is a list of currently supported QVariant types:

If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself. To do this, you can register an interpolator function for a given type. This function takes 3 parameters: the start value, the end value, and the current progress.

Example:

     QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress)
     {
         ...
         return QColor(...);
     }
     ...
     qRegisterAnimationInterpolator<QColor>(myColorInterpolator);

Another option is to reimplement interpolated(), which returns interpolation values for the value being interpolated.

See also QPropertyAnimation, QAbstractAnimation, and The Animation Framework.

Member Type Documentation

typedef QVariantAnimation::KeyValue

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

typedef QVariantAnimation::KeyValues

This is a typedef for QVector<KeyValue>

Property Documentation

currentValue : const QVariant

This property holds the current value of the animation.

This property describes the current value; an interpolated value between the start value and the end value, using the current time for progress. The value itself is obtained from interpolated(), which is called repeatedly as the animation is running.

QVariantAnimation calls the virtual updateCurrentValue() function when the current value changes. This is particularly useful for subclasses that need to track updates. For example, QPropertyAnimation uses this function to animate Qt properties.

Access functions:

QVariant currentValue() const

Notifier signal:

void valueChanged(const QVariant &value)

See also startValue and endValue.

duration : int

This property holds the duration of the animation

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

Access functions:

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

See also QAbstractAnimation::duration().

easingCurve : QEasingCurve

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. Other curves are provided, for instance, QEasingCurve::InCirc, which provides a circular entry curve. Another example is QEasingCurve::InOutElastic, which provides an elastic effect on the values of the interpolated variant.

QVariantAnimation will use the QEasingCurve::valueForProgress() to transform the "normalized progress" (currentTime / totalDuration) of the animation into the effective progress actually used by the animation. It is this effective progress that will be the progress when interpolated() is called. Also, the steps in the keyValues are referring to this effective progress.

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

Access functions:

QEasingCurve easingCurve() const
void setEasingCurve(const QEasingCurve &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.