QGraphicsItemAnimation Class Reference

The QGraphicsItemAnimation class provides simple animation support for QGraphicsItem.

  1. #include <QGraphicsItemAnimation>

This class is deprecated.

Inherits: QObject.

This class was introduced in Qt 4.2.

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:

  1.     QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20);
  2.  
  3.     QTimeLine *timer = new QTimeLine(5000);
  4.     timer->setFrameRange(0, 100);
  5.  
  6.     QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
  7.     animation->setItem(ball);
  8.     animation->setTimeLine(timer);
  9.  
  10.     for (int i = 0; i < 200; ++i)
  11.         animation->setPosAt(i / 200.0, QPointF(i, i));
  12.  
  13.     QGraphicsScene *scene = new QGraphicsScene();
  14.     scene->setSceneRect(0, 0, 250, 250);
  15.     scene->addItem(ball);
  16.  
  17.     QGraphicsView *view = new QGraphicsView(scene);
  18.     view->show();
  19.  
  20.     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 Graphics View Framework.

Public Functions

Toggle details QGraphicsItemAnimation

QGraphicsItemAnimationQGraphicsItemAnimation ( QObject *parent=0 ) ( QObject *parent=0 )

Constructs an animation object with the given parent.

Look up this member in the source code.

Toggle details QGraphicsItemAnimation

~QGraphicsItemAnimation~QGraphicsItemAnimation () () [virtual]

Destroys the animation object.

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

afterAnimationStepafterAnimationStep ( qreal step ) ( qreal step ) [virtual protected]

This method is meant to be overridden in subclasses that need to execute additional code after a new step has taken place. The animation step is provided for use in cases where the action depends on its value.

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

beforeAnimationStepbeforeAnimationStep ( qreal step ) ( qreal step ) [virtual protected]

This method is meant to be overridden by subclassed that needs to execute additional code before a new step takes place. The animation step is provided for use in cases where the action depends on its value.

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

clearclear () ()

Clears the scheduled transformations used for the animation, but retains the item and timeline.

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

horizontalScaleAthorizontalScaleAt ( qreal step ) ( qreal step )const

Returns the horizontal scale for the item at the specified step value.

See also setScaleAt().

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

horizontalShearAthorizontalShearAt ( qreal step ) ( qreal step )const

Returns the horizontal shear for the item at the specified step value.

See also setShearAt().

Look up this member in the source code.

Toggle details QGraphicsItem * QGraphicsItemAnimation

itemitem () ()const

Returns the item on which the animation object operates.

See also setItem().

Look up this member in the source code.

Toggle details QMatrix QGraphicsItemAnimation

matrixAtmatrixAt ( qreal step ) ( qreal step )const

Returns the matrix used to transform the item at the specified step value.

Look up this member in the source code.

Toggle details QPointF QGraphicsItemAnimation

posAtposAt ( qreal step ) ( qreal step )const

Returns the position of the item at the given step value.

See also setPosAt().

Look up this member in the source code.

Toggle details QList <QPair <qreal , QPointF > > QGraphicsItemAnimation

posListposList () ()const

Returns all explicitly inserted positions.

See also posAt() and setPosAt().

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

rotationAtrotationAt ( qreal step ) ( qreal step )const

Returns the angle at which the item is rotated at the specified step value.

See also setRotationAt().

Look up this member in the source code.

Toggle details QList <QPair <qreal , qreal > > QGraphicsItemAnimation

rotationListrotationList () ()const

Returns all explicitly inserted rotations.

See also rotationAt() and setRotationAt().

Look up this member in the source code.

Toggle details QList <QPair <qreal , QPointF > > QGraphicsItemAnimation

scaleListscaleList () ()const

Returns all explicitly inserted scales.

See also verticalScaleAt(), horizontalScaleAt(), and setScaleAt().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setItemsetItem ( QGraphicsItem *item ) ( QGraphicsItem *item )

Sets the specified item to be used in the animation.

See also item().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setPosAtsetPosAt ( qreal step , const QPointF &point ) ( qreal step , const QPointF &point )

Sets the position of the item at the given step value to the point specified.

See also posAt().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setRotationAtsetRotationAt ( qreal step , qreal angle ) ( qreal step , qreal angle )

Sets the rotation of the item at the given step value to the angle specified.

See also rotationAt().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setScaleAtsetScaleAt ( qreal step , qreal sx , qreal sy ) ( qreal step , qreal sx , qreal sy )

Sets the scale of the item at the given step value using the horizontal and vertical scale factors specified by sx and sy.

See also verticalScaleAt() and horizontalScaleAt().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setShearAtsetShearAt ( qreal step , qreal sh , qreal sv ) ( qreal step , qreal sh , qreal sv )

Sets the shear of the item at the given step value using the horizontal and vertical shear factors specified by sh and sv.

See also verticalShearAt() and horizontalShearAt().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setTimeLinesetTimeLine ( QTimeLine *timeLine ) ( QTimeLine *timeLine )

Sets the timeline object used to control the rate of animation to the timeLine specified.

See also timeLine().

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

setTranslationAtsetTranslationAt ( qreal step , qreal dx , qreal dy ...) ( qreal step , qreal dx , qreal dy )

Sets the translation of the item at the given step value using the horizontal and vertical coordinates specified by dx and dy.

See also xTranslationAt() and yTranslationAt().

Look up this member in the source code.

Toggle details QList <QPair <qreal , QPointF > > QGraphicsItemAnimation

shearListshearList () ()const

Returns all explicitly inserted shears.

See also verticalShearAt(), horizontalShearAt(), and setShearAt().

Look up this member in the source code.

Toggle details QTimeLine * QGraphicsItemAnimation

timeLinetimeLine () ()const

Returns the timeline object used to control the rate at which the animation occurs.

See also setTimeLine().

Look up this member in the source code.

Toggle details QList <QPair <qreal , QPointF > > QGraphicsItemAnimation

translationListtranslationList () ()const

Returns all explicitly inserted translations.

See also xTranslationAt(), yTranslationAt(), and setTranslationAt().

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

verticalScaleAtverticalScaleAt ( qreal step ) ( qreal step )const

Returns the vertical scale for the item at the specified step value.

See also setScaleAt().

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

verticalShearAtverticalShearAt ( qreal step ) ( qreal step )const

Returns the vertical shear for the item at the specified step value.

See also setShearAt().

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

xTranslationAtxTranslationAt ( qreal step ) ( qreal step )const

Returns the horizontal translation of the item at the specified step value.

See also setTranslationAt().

Look up this member in the source code.

Toggle details qreal QGraphicsItemAnimation

yTranslationAtyTranslationAt ( qreal step ) ( qreal step )const

Returns the vertical translation of the item at the specified step value.

See also setTranslationAt().

Look up this member in the source code.

Public Slots

Toggle details void QGraphicsItemAnimation

setStepsetStep ( qreal step ) ( qreal step ) [slot]

Sets the current step value for the animation, causing the transformations scheduled at this step to be performed.

Look up this member in the source code.

Toggle details void QGraphicsItemAnimation

resetreset () () [slot] Obsolete function

Resets the item to its starting position and transformation.

You can call setStep(0) instead.

Look up this member in the source code.

Notes provided by the Qt Community

No notes