PySide6.QtWidgets.QGraphicsItemAnimation¶
- class QGraphicsItemAnimation¶
The
QGraphicsItemAnimationclass provides simple animation support forQGraphicsItem.Details
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
The
QGraphicsItemAnimationclass animates aQGraphicsItem. You can schedule changes to the item’s transformation matrix at specified steps. TheQGraphicsItemAnimationclass 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.QGraphicsItemAnimationwill 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 callingsetRotationAt()for different step values. The animations timeline is set with thesetTimeLine()function.An example animation with a timeline follows:
ball = QGraphicsEllipseItem(0, 0, 20, 20) timer = QTimeLine(5000) timer.setFrameRange(0, 100) animation = QGraphicsItemAnimation() animation.setItem(ball) animation.setTimeLine(timer) for i in range(0, 200): animation.setPosAt(i / 200.0, QPointF(i, i)) scene = QGraphicsScene() scene.setSceneRect(0, 0, 250, 250) scene.addItem(ball) view = 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
Synopsis¶
Methods¶
def
__init__()def
clear()def
item()def
posAt()def
posList()def
rotationAt()def
rotationList()def
scaleList()def
setItem()def
setPosAt()def
setRotationAt()def
setScaleAt()def
setShearAt()def
setTimeLine()def
shearList()def
timeLine()def
transformAt()def
xTranslationAt()def
yTranslationAt()
Virtual methods¶
Slots¶
def
setStep()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Constructs an animation object with the given
parent.- 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
stepis provided for use in cases where the action depends on its value.- 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
stepis provided for use in cases where the action depends on its value.- clear()¶
Clears the scheduled transformations used for the animation, but retains the item and timeline.
- horizontalScaleAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the horizontal scale for the item at the specified
stepvalue.See also
- horizontalShearAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the horizontal shear for the item at the specified
stepvalue.See also
- item()¶
- Return type:
Returns the item on which the animation object operates.
See also
Returns the position of the item at the given
stepvalue.See also
Returns all explicitly inserted positions.
See also
- rotationAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the angle at which the item is rotated at the specified
stepvalue.See also
- rotationList()¶
- Return type:
.list of std.pairqreal,qreal
Returns all explicitly inserted rotations.
See also
Returns all explicitly inserted scales.
- setItem(item)¶
- Parameters:
item –
QGraphicsItem
Sets the specified
itemto be used in the animation.See also
Sets the position of the item at the given
stepvalue to thepointspecified.See also
- setRotationAt(step, angle)¶
- Parameters:
step – float
angle – float
Sets the rotation of the item at the given
stepvalue to theanglespecified.See also
- setScaleAt(step, sx, sy)¶
- Parameters:
step – float
sx – float
sy – float
Sets the scale of the item at the given
stepvalue using the horizontal and vertical scale factors specified bysxandsy.See also
- setShearAt(step, sh, sv)¶
- Parameters:
step – float
sh – float
sv – float
Sets the shear of the item at the given
stepvalue using the horizontal and vertical shear factors specified byshandsv.See also
- setStep(x)¶
- Parameters:
x – float
Sets the current
stepvalue 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
timeLinespecified.See also
- setTranslationAt(step, dx, dy)¶
- Parameters:
step – float
dx – float
dy – float
Sets the translation of the item at the given
stepvalue using the horizontal and vertical coordinates specified bydxanddy.See also
Returns all explicitly inserted shears.
Returns the timeline object used to control the rate at which the animation occurs.
See also
- transformAt(step)¶
- Parameters:
step – float
- Return type:
Returns the transform used for the item at the specified
stepvalue.Returns all explicitly inserted translations.
- verticalScaleAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the vertical scale for the item at the specified
stepvalue.See also
- verticalShearAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the vertical shear for the item at the specified
stepvalue.See also
- xTranslationAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the horizontal translation of the item at the specified
stepvalue.See also
- yTranslationAt(step)¶
- Parameters:
step – float
- Return type:
float
Returns the vertical translation of the item at the specified
stepvalue.See also