QGraphicsItemAnimation Class▲
-
Header: QGraphicsItemAnimation
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
-
qmake: QT += widgets
-
Inherits: QObject
-
Group: QGraphicsItemAnimation is part of graphicsview-api
This class is deprecated. We strongly advise against using it in new code.
Detailed Description▲
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-&
gt;setFrameRange(0
, 100
);
QGraphicsItemAnimation *
animation =
new
QGraphicsItemAnimation;
animation-&
gt;setItem(ball);
animation-&
gt;setTimeLine(timer);
for
(int
i =
0
; i &
lt; 200
; ++
i)
animation-&
gt;setPosAt(i /
200.0
, QPointF(i, i));
QGraphicsScene *
scene =
new
QGraphicsScene;
scene-&
gt;setSceneRect(0
, 0
, 250
, 250
);
scene-&
gt;addItem(ball);
QGraphicsView *
view =
new
QGraphicsView(scene);
view-&
gt;show();
timer-&
gt;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▲
See also QTimeLine, Graphics View Framework
Member Function Documentation▲
QGraphicsItemAnimation::QGraphicsItemAnimation(QObject *parent = nullptr)▲
Constructs an animation object with the given parent.
[virtual] QGraphicsItemAnimation::~QGraphicsItemAnimation()▲
Destroys the animation object.
[virtual protected] void QGraphicsItemAnimation::afterAnimationStep(qreal step)▲
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.
[virtual protected] void QGraphicsItemAnimation::beforeAnimationStep(qreal step)▲
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.
void QGraphicsItemAnimation::clear()▲
Clears the scheduled transformations used for the animation, but retains the item and timeline.
qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const▲
Returns the horizontal scale for the item at the specified step value.
See Also▲
See also setScaleAt()
qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const▲
Returns the horizontal shear for the item at the specified step value.
See Also▲
See also setShearAt()
QGraphicsItem *QGraphicsItemAnimation::item() const▲
QPointF QGraphicsItemAnimation::posAt(qreal step) const▲
QList<QPair<qreal, QPointF>> QGraphicsItemAnimation::posList() const▲
qreal QGraphicsItemAnimation::rotationAt(qreal step) const▲
Returns the angle at which the item is rotated at the specified step value.
See Also▲
See also setRotationAt()
QList<QPair<qreal, qreal>> QGraphicsItemAnimation::rotationList() const▲
QList<QPair<qreal, QPointF>> QGraphicsItemAnimation::scaleList() const▲
Returns all explicitly inserted scales.
See Also▲
See also verticalScaleAt(), horizontalScaleAt(), setScaleAt()
void QGraphicsItemAnimation::setItem(QGraphicsItem *item)▲
void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &point)▲
Sets the position of the item at the given step value to the point specified.
See Also▲
See also posAt()
void QGraphicsItemAnimation::setRotationAt(qreal step, qreal angle)▲
Sets the rotation of the item at the given step value to the angle specified.
See Also▲
See also rotationAt()
void QGraphicsItemAnimation::setScaleAt(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▲
See also verticalScaleAt(), horizontalScaleAt()
void QGraphicsItemAnimation::setShearAt(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▲
See also verticalShearAt(), horizontalShearAt()
void QGraphicsItemAnimation::setStep(qreal step)▲
Sets the current step value for the animation, causing the transformations scheduled at this step to be performed.
void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine)▲
Sets the timeline object used to control the rate of animation to the timeLine specified.
See Also▲
See also timeLine()
void QGraphicsItemAnimation::setTranslationAt(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▲
See also xTranslationAt(), yTranslationAt()
QList<QPair<qreal, QPointF>> QGraphicsItemAnimation::shearList() const▲
Returns all explicitly inserted shears.
See Also▲
See also verticalShearAt(), horizontalShearAt(), setShearAt()
QTimeLine *QGraphicsItemAnimation::timeLine() const▲
Returns the timeline object used to control the rate at which the animation occurs.
See Also▲
See also setTimeLine()
[since 5.14] QTransform QGraphicsItemAnimation::transformAt(qreal step) const▲
Returns the transform used for the item at the specified step value.
This function was introduced in Qt 5.14.
QList<QPair<qreal, QPointF>> QGraphicsItemAnimation::translationList() const▲
Returns all explicitly inserted translations.
See Also▲
See also xTranslationAt(), yTranslationAt(), setTranslationAt()
qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const▲
Returns the vertical scale for the item at the specified step value.
See Also▲
See also setScaleAt()
qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const▲
Returns the vertical shear for the item at the specified step value.
See Also▲
See also setShearAt()
qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const▲
Returns the horizontal translation of the item at the specified step value.
See Also▲
See also setTranslationAt()
qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const▲
Returns the vertical translation of the item at the specified step value.
See Also▲
See also setTranslationAt()