Home

QtAnimation Class Reference
[QtGui module]

The QtAnimation class animates properties for QObject, QWidget, and QGraphicsItem More...

 #include <QtAnimation>

This class is under development and is subject to change.

Inherits QtAbstractAnimation.

This class was introduced in qtanimationframework 4.5.

Properties

Public Functions

Signals

Static Public Members

Protected Functions

Additional Inherited Members


Detailed Description

The QtAnimation class animates properties for QObject, QWidget, and QGraphicsItem

This class is part of {The Animation Framework}. You can use QtAnimation by itself as a simple animation class, or as part of more complex animations through QtAnimationGroup or QtTransition.

The most common way to use QtAnimation is to construct an instance of it by passing a pointer to a QObject, a QWidget or a QGraphicsItem, and the name of the property you would like to animate, to QtAnimation's constructor. You can then set start and target values for the property by calling setStartValue() and setTargetValue(), 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, widget or item.

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.

The start value of the animation is optional. If you do not set any start value, the animation will operate on the target's current property value at the point when the animation was started. You can call setStartValue() to set the start value, and setTargetValue() to set the target value for the animated property. When used as part of a QtTransition, it's common to omit both the start and target values, as these are set automatically by the transition as it is initialized.

Animations can operate on QObjects, QWidgets and QGraphicsItems. QGraphicsItem does not inherit QObject, and does not provide any properties as such. For convenience however, QtAnimation emulates properties for QGraphicsItem, so that you can animate an item's position, geometry or opacity, just like with QObjects. You can choose to assign a target object by either calling setTargetObject() or by passing a QObject pointer to QtAnimation's constructor, or you can assign an item as the target by calling setTargetItem(), or by passing an item pointer to QtAnimation's constructor.

QtAnimation also declares the virtual currentValueChanged() function, which makes it suitable to use as a base class for custom animations that are based on QVariant or property interpolation.

See also QtAnimationGroup, QtAbstractAnimation, QtTransition, and The Animation Framework.


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:

See also startValue and targetValue.

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:

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 target 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:

propertyName : QString

This property holds the target property name for this animation.

This property defines the target property name for this animation. The property name is required for the animation to operate.

Access functions:

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 target when the animation is started.

Access functions:

See also targetValue.

targetItem : QGraphicsItem *

This property holds the target QGraphicsItem for this animation.

This property defines the target QGraphicsItem for this animation. If you want to animate properties for a QObject instead, you can call setTargetObject(). If the animation has no target, or if the target is a QObject, this property will be 0.

Access functions:

See also targetObject.

targetObject : QObject *

This property holds the target QObject for this animation.

This property defines the target QObject for this animation. If you want to animate properties for a QGraphicsItem instead, you can call setTargetItem(). If the animation has no target, or if the target is a QGraphicsItem, this property will be 0.

Access functions:

See also targetItem.

targetValue : QVariant

This property holds the target value of the animation.

This property describes the target value of the animation.

Access functions:

See also startValue.


Member Function Documentation

QtAnimation::QtAnimation ( QObject * parent = 0 )

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

QtAnimation::QtAnimation ( QObject * target, const QByteArray & propertyName, QObject * parent = 0 )

Construct a QtAnimation object. parent is passed to QObject's constructor. The animation changes the property propertyName on target. The default duration is 250ms.

See also targetObject and propertyName.

QtAnimation::QtAnimation ( QGraphicsItem * target, const QByteArray & propertyName, QObject * parent = 0 )

Construct a QtAnimation object. parent is passed to QObject's constructor. The animation changes the property propertyName on target. The default duration is 250ms.

See also targetItem and propertyName.

QtAnimation::~QtAnimation ()

Destroys the QtAnimation instance.

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

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

See also setDuration() and duration().

QtAnimation * QtAnimation::geometryAnimation ( QGraphicsWidget * widget, const QRectF & rect, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

convenience function to construct a QtAnimation that animates the "geometry" property.

This is a convenience function that you can use to animate the "geometry" property of widget. rect it the target rectangle, duration is the desired duration and with easing you can specify the easing curve you want to use. It also provides a type-safe way of specifying the property you want to animate.The animation returned can either be added to a QtAnimationGroup or can be started immediately.

See also posAnimation(), opacityAnimation(), propertyAnimation(), and visibleAnimation().

QtAnimation * QtAnimation::geometryAnimation ( QWidget * widget, const QRect & rect, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

This is an overloaded member function, provided for convenience.

This is a convenience function that you can use to construct a simple animation with a single line of code. Use this if you want to animate a QWidget.

See also geometryAnimation(), opacityAnimation(), propertyAnimation(), and visibleAnimation().

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.

QtAnimation * QtAnimation::opacityAnimation ( QGraphicsItem * item, qreal opacity, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

convenience function to construct a QtAnimation that animates the "opacity" property.

This is a convenience function that you can use to animate the "opacity" property of item. opacity it the target opacity, duration is the desired duration and with easing you can specify the easing curve you want to use. It also provides a type-safe way of specifying the property you want to animate.The animation returned can either be added to a QtAnimationGroup or can be started immediately.

See also posAnimation(), geometryAnimation(), propertyAnimation(), and visibleAnimation().

QtAnimation * QtAnimation::posAnimation ( QGraphicsItem * item, const QPointF & pos, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

convenience function to construct a QtAnimation that animates the "pos" property.

This is a convenience function that you can use to animate the "pos" property of item. pos it the target position, duration is the desired duration and with easing you can specify the easing curve you want to use. It also provides a type-safe way of specifying the property you want to animate. The animation returned can either be added to a QtAnimationGroup or can be started immediately.

Calling this convenience function with the following arguments:

 QtAnimation *anim = QtAnimation::posAnimation(item, QPointF(240, 0), 1000, QtEasingCurve::EaseInOut));

is the same as this code:

 QtAnimation *anim = new QtAnimation(item, "pos");
 anim->setDuration(1000);
 anim->setEasingCurve(QtEasingCurve::EaseInOut);
 anim->setTargetValue(QPointF(240, 0));

If you want to immediately start the animation and let the animation delete itself when it is finished you can do:

 QGraphicsItem *item;
 QtAnimation::posAnimation(item, QPointF(240, 0), 250, QtEasingCurve::EaseInOut)->start(QtAnimation::DeleteWhenFinished);

See also geometryAnimation(), opacityAnimation(), propertyAnimation(), and visibleAnimation().

QtAnimation * QtAnimation::posAnimation ( QWidget * widget, const QPoint & pos, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

This is an overloaded member function, provided for convenience.

This is a convenience function that you can use to construct a simple animation with a single line of code. Use this if you want to animate widget.

See also geometryAnimation(), opacityAnimation(), propertyAnimation(), and visibleAnimation().

QtAnimation * QtAnimation::propertyAnimation ( QGraphicsItem * item, const char * propertyName, const QVariant & value, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

convenience function to construct a QtAnimation that animates the property propertyName.

This is a convenience function that you can use to animate the propertyName property of item. value it the target value, duration is the desired duration and with easing you can specify the easing curve you want to use. It also provides a type-safe way of specifying the property you want to animate.The animation returned can either be added to a QtAnimationGroup or can be started immediately.

See also posAnimation(), geometryAnimation(), opacityAnimation(), and visibleAnimation().

QtAnimation * QtAnimation::propertyAnimation ( QGraphicsWidget * widget, const char * propertyName, const QVariant & value, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

This is an overloaded member function, provided for convenience.

This is a convenience function that you can use to construct a simple animation with a single line of code. Use this if you want to animate widget.

See also posAnimation(), geometryAnimation(), opacityAnimation(), and visibleAnimation().

QtAnimation * QtAnimation::propertyAnimation ( QObject * object, const char * propertyName, const QVariant & value, int duration = 250, const QtEasingCurve & easing = QtEasingCurve() )   [static]

This is an overloaded member function, provided for convenience.

This is a convenience function that you can use to construct a simple animation with a single line of code. Use this if you want to animate object.

See also posAnimation(), geometryAnimation(), opacityAnimation(), and visibleAnimation().

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

This virtual function is called by QtAnimation whenever the current value changes. value is the new, updated value. By reimplementing this function in a subclass of QtAnimation, you can easily apply the new value to a custom animation target.

See also currentValue and currentTime.

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

QtAnimation emits this signal whenever the current value changes.

See also currentValue, startValue, and targetValue.

QtAnimation * QtAnimation::visibleAnimation ( QGraphicsItem * item, bool visible )   [static]

convenience function to construct a QtAnimation that animates the "visible" property.

This is a convenience function that you can use to animate the "visible" property of item. visible it the target visibility, duration is the desired duration and with easing you can specify the easing curve you want to use. It also provides a type-safe way of specifying the property you want to animate.The animation returned can either be added to a QtAnimationGroup or can be started immediately.

See also posAnimation(), geometryAnimation(), opacityAnimation(), and propertyAnimation().

QtAnimation * QtAnimation::visibleAnimation ( QWidget * widget, bool visible )   [static]

This is an overloaded member function, provided for convenience.

This is a convenience function that you can use to construct a simple animation with a single line of code. Use this if you want to animate a QWidget.

See also posAnimation(), geometryAnimation(), opacityAnimation(), and propertyAnimation().


Copyright © 2008 Nokia Trademarks
Qt Solutions