QGraphicsItemAnimation¶
The
QGraphicsItemAnimation
class provides simple animation support forQGraphicsItem
. More…
Synopsis¶
Functions¶
def
clear
()def
horizontalScaleAt
(step)def
horizontalShearAt
(step)def
item
()def
matrixAt
(step)def
posAt
(step)def
posList
()def
rotationAt
(step)def
rotationList
()def
scaleList
()def
setItem
(item)def
setPosAt
(step, pos)def
setRotationAt
(step, angle)def
setScaleAt
(step, sx, sy)def
setShearAt
(step, sh, sv)def
setTimeLine
(timeLine)def
setTranslationAt
(step, dx, dy)def
shearList
()def
timeLine
()def
transformAt
(step)def
translationList
()def
verticalScaleAt
(step)def
verticalShearAt
(step)def
xTranslationAt
(step)def
yTranslationAt
(step)
Virtual functions¶
def
afterAnimationStep
(step)def
beforeAnimationStep
(step)
Slots¶
Detailed Description¶
The
QGraphicsItemAnimation
class animates aQGraphicsItem
. You can schedule changes to the item’s transformation matrix at specified steps. TheQGraphicsItemAnimation
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 thesetStep()
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’svalueChanged()
signal is then connected to thesetStep()
slot. For example, you can set up an item for rotation by callingsetRotationAt()
for different step values. The animations timeline is set with thesetTimeLine()
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
Graphics View Framework
- class PySide2.QtWidgets.QGraphicsItemAnimation([parent=None])¶
- param parent:
Constructs an animation object with the given
parent
.
- PySide2.QtWidgets.QGraphicsItemAnimation.afterAnimationStep(step)¶
- Parameters:
step – float
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.
- PySide2.QtWidgets.QGraphicsItemAnimation.beforeAnimationStep(step)¶
- Parameters:
step – float
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.
- PySide2.QtWidgets.QGraphicsItemAnimation.clear()¶
Clears the scheduled transformations used for the animation, but retains the item and timeline.
- PySide2.QtWidgets.QGraphicsItemAnimation.horizontalScaleAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the horizontal scale for the item at the specified
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.horizontalShearAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the horizontal shear for the item at the specified
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.item()¶
- Return type:
Returns the item on which the animation object operates.
See also
- PySide2.QtWidgets.QGraphicsItemAnimation.matrixAt(step)¶
- Parameters:
step – float
- Return type:
Note
This function is deprecated.
Returns the matrix used to transform the item at the specified
step
value.Use
transformAt()
instead
- PySide2.QtWidgets.QGraphicsItemAnimation.posAt(step)¶
- Parameters:
step – float
- Return type:
Returns the position of the item at the given
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.posList()¶
- Return type:
Returns all explicitly inserted positions.
See also
- PySide2.QtWidgets.QGraphicsItemAnimation.reset()¶
Note
This function is deprecated.
Resets the item to its starting position and transformation.
You can call
setStep
(0) instead.
- PySide2.QtWidgets.QGraphicsItemAnimation.rotationAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the angle at which the item is rotated at the specified
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.rotationList()¶
- Return type:
Returns all explicitly inserted rotations.
See also
- PySide2.QtWidgets.QGraphicsItemAnimation.scaleList()¶
- Return type:
Returns all explicitly inserted scales.
- PySide2.QtWidgets.QGraphicsItemAnimation.setItem(item)¶
- Parameters:
Sets the specified
item
to be used in the animation.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.setPosAt(step, pos)¶
- Parameters:
step – float
pos –
PySide2.QtCore.QPointF
Sets the position of the item at the given
step
value to thepoint
specified.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.setRotationAt(step, angle)¶
- Parameters:
step – float
angle – float
Sets the rotation of the item at the given
step
value to theangle
specified.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.setScaleAt(step, sx, sy)¶
- Parameters:
step – float
sx – float
sy – float
Sets the scale of the item at the given
step
value using the horizontal and vertical scale factors specified bysx
andsy
.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.setShearAt(step, sh, sv)¶
- Parameters:
step – float
sh – float
sv – float
Sets the shear of the item at the given
step
value using the horizontal and vertical shear factors specified bysh
andsv
.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.setStep(x)¶
- Parameters:
x – float
Sets the current
step
value for the animation, causing the transformations scheduled at this step to be performed.
- PySide2.QtWidgets.QGraphicsItemAnimation.setTimeLine(timeLine)¶
- Parameters:
timeLine –
PySide2.QtCore.QTimeLine
Sets the timeline object used to control the rate of animation to the
timeLine
specified.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.setTranslationAt(step, dx, dy)¶
- Parameters:
step – float
dx – float
dy – float
Sets the translation of the item at the given
step
value using the horizontal and vertical coordinates specified bydx
anddy
.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.shearList()¶
- Return type:
Returns all explicitly inserted shears.
- PySide2.QtWidgets.QGraphicsItemAnimation.timeLine()¶
- Return type:
Returns the timeline object used to control the rate at which the animation occurs.
See also
- PySide2.QtWidgets.QGraphicsItemAnimation.transformAt(step)¶
- Parameters:
step – float
- Return type:
Returns the transform used for the item at the specified
step
value.
- PySide2.QtWidgets.QGraphicsItemAnimation.translationList()¶
- Return type:
Returns all explicitly inserted translations.
- PySide2.QtWidgets.QGraphicsItemAnimation.verticalScaleAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the vertical scale for the item at the specified
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.verticalShearAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the vertical shear for the item at the specified
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.xTranslationAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the horizontal translation of the item at the specified
step
value.See also
- PySide2.QtWidgets.QGraphicsItemAnimation.yTranslationAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the vertical translation of the item at the specified
step
value.See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.