The QGraphicsItemAnimation class provides simple animation support for QGraphicsItem . 更多...
头: | #include <QGraphicsItemAnimation> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QObject |
状态: | Deprecated |
This class is deprecated. We strongly advise against using it in new code.
QGraphicsItemAnimation (QObject * parent = nullptr) | |
virtual | ~QGraphicsItemAnimation () |
void | clear () |
qreal | horizontalScaleAt (qreal step ) const |
qreal | horizontalShearAt (qreal step ) const |
QGraphicsItem * | item () const |
QPointF | posAt (qreal step ) const |
QList<QPair<qreal, QPointF>> | posList () const |
qreal | rotationAt (qreal step ) const |
QList<QPair<qreal, qreal>> | rotationList () const |
QList<QPair<qreal, QPointF>> | scaleList () const |
void | setItem (QGraphicsItem * item ) |
void | setPosAt (qreal step , const QPointF & point ) |
void | setRotationAt (qreal step , qreal angle ) |
void | setScaleAt (qreal step , qreal sx , qreal sy ) |
void | setShearAt (qreal step , qreal sh , qreal sv ) |
void | setTimeLine (QTimeLine * timeLine ) |
void | setTranslationAt (qreal step , qreal dx , qreal dy ) |
QList<QPair<qreal, QPointF>> | shearList () const |
QTimeLine * | timeLine () const |
QTransform | transformAt (qreal step ) const |
QList<QPair<qreal, QPointF>> | translationList () const |
qreal | verticalScaleAt (qreal step ) const |
qreal | verticalShearAt (qreal step ) const |
qreal | xTranslationAt (qreal step ) const |
qreal | yTranslationAt (qreal step ) const |
void | setStep (qreal step ) |
virtual void | afterAnimationStep (qreal step ) |
virtual void | beforeAnimationStep (qreal step ) |
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()
函数。
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
() 函数。
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.
Constructs an animation object with the given parent .
[virtual noexcept]
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.
Clears the scheduled transformations used for the animation, but retains the item and timeline.
Returns the horizontal scale for the item at the specified step 值。
另请参阅 setScaleAt ().
Returns the horizontal shear for the item at the specified step 值。
另请参阅 setShearAt ().
Returns the item on which the animation object operates.
另请参阅 setItem ().
Returns the position of the item at the given step 值。
另请参阅 setPosAt ().
Returns all explicitly inserted positions.
Returns the angle at which the item is rotated at the specified step 值。
另请参阅 setRotationAt ().
Returns all explicitly inserted rotations.
另请参阅 rotationAt () 和 setRotationAt ().
Returns all explicitly inserted scales.
另请参阅 verticalScaleAt (), horizontalScaleAt (),和 setScaleAt ().
设置指定 item to be used in the animation.
另请参阅 item ().
Sets the position of the item at the given step value to the point 指定。
另请参阅 posAt ().
Sets the rotation of the item at the given step value to the angle 指定。
另请参阅 rotationAt ().
Sets the scale of the item at the given step value using the horizontal and vertical scale factors specified by sx and sy .
另请参阅 verticalScaleAt () 和 horizontalScaleAt ().
Sets the shear of the item at the given step value using the horizontal and vertical shear factors specified by sh and sv .
另请参阅 verticalShearAt () 和 horizontalShearAt ().
[slot]
void
QGraphicsItemAnimation::
setStep
(
qreal
step
)
设置当前 step value for the animation, causing the transformations scheduled at this step to be performed.
Sets the timeline object used to control the rate of animation to the timeLine 指定。
另请参阅 timeLine ().
Sets the translation of the item at the given step value using the horizontal and vertical coordinates specified by dx and dy .
另请参阅 xTranslationAt () 和 yTranslationAt ().
Returns all explicitly inserted shears.
另请参阅 verticalShearAt (), horizontalShearAt (),和 setShearAt ().
Returns the timeline object used to control the rate at which the animation occurs.
另请参阅 setTimeLine ().
Returns the transform used for the item at the specified step 值。
Returns all explicitly inserted translations.
另请参阅 xTranslationAt (), yTranslationAt (),和 setTranslationAt ().
Returns the vertical scale for the item at the specified step 值。
另请参阅 setScaleAt ().
Returns the vertical shear for the item at the specified step 值。
另请参阅 setShearAt ().
Returns the horizontal translation of the item at the specified step 值。
另请参阅 setTranslationAt ().
Returns the vertical translation of the item at the specified step 值。
另请参阅 setTranslationAt ().