|  | Home · Overviews · Examples |

# QGraphicsItemAnimation Class Reference
[com.trolltech.qt.gui module]

The `QGraphicsItemAnimation` class provides simple animation support for `QGraphicsItem`. More...

Inherits `QObject`.

## Detailed Description

The `QGraphicsItemAnimation` class provides simple animation support for `QGraphicsItem`.

The `QGraphicsItemAnimation` class animates a `QGraphicsItem`. You can schedule changes to the item's transformation matrix at specified steps. The `QGraphicsItemAnimation` class has a current step value. When this value changes the transformations scheduled at that step are performed. The current step of the animation is set with the `setStep()` function.

`QGraphicsItemAnimation` will do a simple linear interpolation between the nearest adjacent scheduled changes to calculate the matrix. For instance, if you set the position of an item at values 0.0 and 1.0, the animation will show the item moving in a straight line between these positions. The same is true for scaling and rotation.

It is usual to use the class with a `QTimeLine`. The timeline's valueChanged() signal is then connected to the `setStep()` slot. For example, you can set up an item for rotation by calling `setRotationAt()` for different step values. The animations timeline is set with the `setTimeLine` function.

An example animation with a timeline follows:

            QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);

            QTimeLine *timer = new QTimeLine(5000);
            timer->setFrameRange(0, 100);

            QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
            animation->setItem(ball);
            animation->setTimeLine(timer);

            for (int i = 0; i < 200; ++i)
                animation->setPosAt(i / 200.0, QPointF(i, i));

            QGraphicsScene *scene = new QGraphicsScene();
            scene->setSceneRect(0, 0, 250, 250);
            scene->addItem(ball);

            QGraphicsView *view = new QGraphicsView(scene);
            view->show();

            timer->start();

Note that steps lie between 0.0 and 1.0. It may be necessary to use setUpdateInterval(). The default update interval is 40 ms. A scheduled transformation cannot be removed when set, so scheduling several transformations of the same kind (e.g., rotations) at the same step is not recommended.

See also `QTimeLine` and The Graphics View Framework.