内容表

上一话题

QGraphicsItem

下一话题

QGraphicsItemGroup

QGraphicsItemAnimation

QGraphicsItemAnimation class provides simple animation support for QGraphicsItem . 更多

Inheritance diagram of PySide2.QtWidgets.QGraphicsItemAnimation

概要

函数

虚函数

详细描述

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.

class QGraphicsItemAnimation ( [ parent=None ] )
param parent

QObject

Constructs an animation object with the given parent .

PySide2.QtWidgets.QGraphicsItemAnimation. afterAnimationStep ( step )
参数

step qreal

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 )
参数

step qreal

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 )
参数

step qreal

返回类型

qreal

Returns the horizontal scale for the item at the specified step 值。

另请参阅

setScaleAt()

PySide2.QtWidgets.QGraphicsItemAnimation. horizontalShearAt ( step )
参数

step qreal

返回类型

qreal

Returns the horizontal shear for the item at the specified step 值。

另请参阅

setShearAt()

PySide2.QtWidgets.QGraphicsItemAnimation. item ( )
返回类型

QGraphicsItem

Returns the item on which the animation object operates.

另请参阅

setItem()

PySide2.QtWidgets.QGraphicsItemAnimation. matrixAt ( step )
参数

step qreal

返回类型

QMatrix

注意

此函数被弃用。

Returns the matrix used to transform the item at the specified step 值。

使用 transformAt() instead

PySide2.QtWidgets.QGraphicsItemAnimation. posAt ( step )
参数

step qreal

返回类型

QPointF

Returns the position of the item at the given step 值。

另请参阅

setPosAt()

PySide2.QtWidgets.QGraphicsItemAnimation. posList ( )
返回类型

Returns all explicitly inserted positions.

PySide2.QtWidgets.QGraphicsItemAnimation. reset ( )

注意

此函数被弃用。

Resets the item to its starting position and transformation.

可以调用 setStep (0) instead.

PySide2.QtWidgets.QGraphicsItemAnimation. rotationAt ( step )
参数

step qreal

返回类型

qreal

Returns the angle at which the item is rotated at the specified step 值。

另请参阅

setRotationAt()

PySide2.QtWidgets.QGraphicsItemAnimation. rotationList ( )
返回类型

Returns all explicitly inserted rotations.

PySide2.QtWidgets.QGraphicsItemAnimation. scaleList ( )
返回类型

Returns all explicitly inserted scales.

PySide2.QtWidgets.QGraphicsItemAnimation. setItem ( item )
参数

item QGraphicsItem

设置指定 item to be used in the animation.

另请参阅

item()

PySide2.QtWidgets.QGraphicsItemAnimation. setPosAt ( step , pos )
参数
  • step qreal

  • pos QPointF

Sets the position of the item at the given step value to the point 指定。

另请参阅

posAt()

PySide2.QtWidgets.QGraphicsItemAnimation. setRotationAt ( step , angle )
参数
  • step qreal

  • angle qreal

Sets the rotation of the item at the given step value to the angle 指定。

另请参阅

rotationAt()

PySide2.QtWidgets.QGraphicsItemAnimation. setScaleAt ( step , sx , sy )
参数
  • step qreal

  • sx qreal

  • sy qreal

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

PySide2.QtWidgets.QGraphicsItemAnimation. setShearAt ( step , sh , sv )
参数
  • step qreal

  • sh qreal

  • sv qreal

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

PySide2.QtWidgets.QGraphicsItemAnimation. setStep ( x )
参数

x qreal

设置当前 step value for the animation, causing the transformations scheduled at this step to be performed.

PySide2.QtWidgets.QGraphicsItemAnimation. setTimeLine ( timeLine )
参数

timeLine QTimeLine

Sets the timeline object used to control the rate of animation to the timeLine 指定。

另请参阅

timeLine()

PySide2.QtWidgets.QGraphicsItemAnimation. setTranslationAt ( step , dx , dy )
参数
  • step qreal

  • dx qreal

  • dy qreal

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

PySide2.QtWidgets.QGraphicsItemAnimation. shearList ( )
返回类型

Returns all explicitly inserted shears.

PySide2.QtWidgets.QGraphicsItemAnimation. timeLine ( )
返回类型

QTimeLine

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

另请参阅

setTimeLine()

PySide2.QtWidgets.QGraphicsItemAnimation. transformAt ( step )
参数

step qreal

返回类型

QTransform

Returns the transform used for the item at the specified step 值。

PySide2.QtWidgets.QGraphicsItemAnimation. translationList ( )
返回类型

Returns all explicitly inserted translations.

PySide2.QtWidgets.QGraphicsItemAnimation. verticalScaleAt ( step )
参数

step qreal

返回类型

qreal

Returns the vertical scale for the item at the specified step 值。

另请参阅

setScaleAt()

PySide2.QtWidgets.QGraphicsItemAnimation. verticalShearAt ( step )
参数

step qreal

返回类型

qreal

Returns the vertical shear for the item at the specified step 值。

另请参阅

setShearAt()

PySide2.QtWidgets.QGraphicsItemAnimation. xTranslationAt ( step )
参数

step qreal

返回类型

qreal

Returns the horizontal translation of the item at the specified step 值。

PySide2.QtWidgets.QGraphicsItemAnimation. yTranslationAt ( step )
参数

step qreal

返回类型

qreal

Returns the vertical translation of the item at the specified step 值。