QPropertyAnimation Class Reference

The QPropertyAnimation class animates Qt properties

  1. #include <QPropertyAnimation>

Inherits: QVariantAnimation.

This class was introduced in Qt 4.6.

Detailed Description

The QPropertyAnimation class animates Qt properties

QPropertyAnimation interpolates over Qt properties. As property values are stored in QVariants, the class inherits QVariantAnimation, and supports animation of the same variant types as its super class.

A class declaring properties must be a QObject. To make it possible to animate a property, it must provide a setter (so that QPropertyAnimation can set the property's value). Note that this makes it possible to animate many of Qt's widgets. Let's look at an example:

  1. QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
  2. animation->setDuration(10000);
  3. animation->setStartValue(QRect(0, 0, 100, 30));
  4. animation->setEndValue(QRect(250, 250, 100, 30));
  5.  
  6. animation->start();

The property name and the QObject instance of which property should be animated are passed to the constructor. You can then specify the start and end value of the property. The procedure is equal for properties in classes you have implemented yourself--just check with QVariantAnimation that your QVariant type is supported.

The QVariantAnimation class description explains how to set up the animation in detail. Note, however, that if a start value is not set, the property will start at the value it had when the QPropertyAnimation instance was created.

QPropertyAnimation works like a charm on its own. For complex animations that, for instance, contain several objects, QAnimationGroup is provided. An animation group is an animation that can contain other animations, and that can manage when its animations are played. Look at QParallelAnimationGroup for an example.

See also QVariantAnimation, QAnimationGroup, and The Animation Framework.

Properties

Toggle detailspropertyNamepropertyName : QByteArray

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:

Look up this member in the source code.

Toggle detailstargetObjecttargetObject : QObject *

This property holds the target QObject for this animation.

This property defines the target QObject for this animation.

Access functions:

Look up this member in the source code.

    Public Functions

    Toggle details QPropertyAnimation

    QPropertyAnimationQPropertyAnimation ( QObject *parent=0 ) ( QObject *parent=0 )

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

    Look up this member in the source code.

    Toggle details QPropertyAnimation

    QPropertyAnimationQPropertyAnimation ( QObject *target , const QByteArray &propertyName , QObject *parent=0 ...) ( QObject *target , const QByteArray &propertyName , QObject *parent=0 )

    Construct a QPropertyAnimation 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.

    Look up this member in the source code.

    Toggle details QPropertyAnimation

    ~QPropertyAnimation~QPropertyAnimation () ()

    Destroys the QPropertyAnimation instance.

    Look up this member in the source code.

    Toggle details bool QPropertyAnimation

    eventevent ( QEvent *event ) ( QEvent *event ) [virtual protected]

    Reimplemented from QObject::event().

    Look up this member in the source code.

    Toggle details void QPropertyAnimation

    updateCurrentValueupdateCurrentValue ( const QVariant &value ) ( const QVariant &value ) [virtual protected]

    Reimplemented from QVariantAnimation::updateCurrentValue().

    This virtual function is called by QVariantAnimation whenever the current value changes. value is the new, updated value. It updates the current value of the property on the target object.

    See also currentValue and currentTime.

    Look up this member in the source code.

    Toggle details void QPropertyAnimation

    updateStateupdateState ( QAbstractAnimation::State newState , QAbstractAnimation::State oldState ...) ( QAbstractAnimation::State newState , QAbstractAnimation::State oldState ) [virtual protected]

    Reimplemented from QAbstractAnimation::updateState().

    If the startValue is not defined when the state of the animation changes from Stopped to Running, the current property value is used as the initial value for the animation.

    Look up this member in the source code.

      Notes provided by the Qt Community
      Best Practice
      • 5

      Votes: 3

      Coverage: Qt library 4.7, 4.8, 5.0

      Picture of francomartins francomartins

      Lab Rat
      9 notes

      QPropretyAnimation

      1. QPropertyAnimation *animation = new QPropertyAnimation(this->parent(),"windowOpacity");
      2. animation->setDuration(1000);
      3. animation->setStartValue(0.0);
      4. animation->setEndValue(1.0);
      5. animation->setEasingCurve(QEasingCurve::OutCubic);
      6. animation->start();

      [Revisions]