QGraphicsItemAnimation Class
QGraphicsItemAnimation 类为QGraphicsItem 提供简单的动画支持。更多
Header: | #include <QGraphicsItemAnimation> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QObject |
状态: | 已废弃 |
该类已被弃用。我们强烈建议不要在新代码中使用它。
公共函数
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<std::pair<qreal, QPointF>> | posList() const |
qreal | rotationAt(qreal step) const |
QList<std::pair<qreal, qreal>> | rotationList() const |
QList<std::pair<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<std::pair<qreal, QPointF>> | shearList() const |
QTimeLine * | timeLine() const |
QTransform | transformAt(qreal step) const |
QList<std::pair<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) |
详细说明
QGraphicsItemAnimation 类可实现QGraphicsItem 的动画效果。您可以按指定步数安排项目变换矩阵的变化。QGraphicsItemAnimation 类有一个当前步长值。当该值发生变化时,就会执行在该步骤安排的变换。动画的当前步长由setStep()
函数设置。
QGraphicsItemAnimation 将在最近的相邻计划变化之间进行简单的线性插值,以计算矩阵。例如,如果将项目的位置设置为 0.0 和 1.0,动画将显示项目在这两个位置之间直线移动。缩放和旋转也是如此。
通常情况下,该类与QTimeLine 一起使用。然后,时间线的valueChanged() 信号就会连接到setStep()
插槽。例如,您可以通过调用setRotationAt()
来设置不同步长值的旋转项目。动画时间轴是通过setTimeLine() 函数设置的。
下面是一个带有时间轴的动画示例:
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();
请注意,步长介于 0.0 和 1.0 之间。可能需要使用setUpdateInterval() 函数。默认更新间隔为 40 毫秒。已调度的变换在设置后无法移除,因此不建议在同一步骤中调度多个同类变换(如旋转)。
成员函数文档
QGraphicsItemAnimation::QGraphicsItemAnimation(QObject *parent = nullptr)
用给定的parent 构建一个动画对象。
[virtual noexcept]
QGraphicsItemAnimation::~QGraphicsItemAnimation()
销毁动画对象。
[virtual protected]
void QGraphicsItemAnimation::afterAnimationStep(qreal step)
如果子类需要在执行新步骤后执行附加代码,则可以重载该方法。动画step 可用于动作取决于其值的情况。
[virtual protected]
void QGraphicsItemAnimation::beforeAnimationStep(qreal step)
如果子类需要在新步骤开始前执行额外代码,则可以重载该方法。动画step 可用于动作取决于其值的情况。
void QGraphicsItemAnimation::clear()
清除动画中使用的预定变换,但保留项目和时间线。
qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const
以指定的step 值返回项目的水平缩放比例。
另请参阅 setScaleAt().
qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const
返回项目在指定step 值处的水平剪切力。
另请参阅 setShearAt().
QGraphicsItem *QGraphicsItemAnimation::item() const
返回动画对象操作的项目。
另请参阅 setItem()。
QPointF QGraphicsItemAnimation::posAt(qreal step) const
返回项目在给定step 值处的位置。
另请参阅 setPosAt().
QList<std::pair<qreal, QPointF>> QGraphicsItemAnimation::posList() const
返回所有明确插入的位置。
qreal QGraphicsItemAnimation::rotationAt(qreal step) const
返回项目在指定的step 值上旋转的角度。
另请参阅 setRotationAt()。
QList<std::pair<qreal, qreal>> QGraphicsItemAnimation::rotationList() const
返回所有明确插入的旋转。
另请参阅 rotationAt() 和setRotationAt()。
QList<std::pair<qreal, QPointF>> QGraphicsItemAnimation::scaleList() const
返回所有明确插入的刻度。
另请参见 verticalScaleAt()、horizontalScaleAt() 和setScaleAt()。
void QGraphicsItemAnimation::setItem(QGraphicsItem *item)
设置动画中使用的指定item 。
另请参阅 item().
void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &point)
将给定step 值处的项目位置设置为指定的point 。
另请参阅 posAt().
void QGraphicsItemAnimation::setRotationAt(qreal step, qreal angle)
将给定step 值处的项目旋转设置为指定的angle 。
另请参阅 rotationAt().
void QGraphicsItemAnimation::setScaleAt(qreal step, qreal sx, qreal sy)
使用sx 和sy 指定的水平和垂直比例因子,在给定的step 值上设置项目的比例。
另请参阅 verticalScaleAt() 和horizontalScaleAt()。
void QGraphicsItemAnimation::setShearAt(qreal step, qreal sh, qreal sv)
使用sh 和sv 指定的水平和垂直剪切系数,设置step 给定值处的项目剪切力。
另请参阅 verticalShearAt() 和horizontalShearAt()。
[slot]
void QGraphicsItemAnimation::setStep(qreal step)
设置动画的当前step 值,从而执行在此步骤中安排的变换。
void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine)
将用于控制动画速率的时间线对象设置为指定的timeLine 。
另请参阅 timeLine().
void QGraphicsItemAnimation::setTranslationAt(qreal step, qreal dx, qreal dy)
使用dx 和dy 指定的横坐标和纵坐标,在给定的step 值处设置项目的平移。
另请参阅 xTranslationAt() 和yTranslationAt()。
QList<std::pair<qreal, QPointF>> QGraphicsItemAnimation::shearList() const
返回所有明确插入的剪切。
另请参阅 verticalShearAt()、horizontalShearAt() 和setShearAt()。
QTimeLine *QGraphicsItemAnimation::timeLine() const
返回用于控制动画播放速度的时间轴对象。
另请参阅 setTimeLine()。
QTransform QGraphicsItemAnimation::transformAt(qreal step) const
返回项目在指定的step 值上使用的变换。
QList<std::pair<qreal, QPointF>> QGraphicsItemAnimation::translationList() const
返回所有明确插入的翻译。
另请参阅 xTranslationAt()、yTranslationAt() 和setTranslationAt()。
qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const
以指定的step 值返回项目的垂直缩放比例。
另请参阅 setScaleAt().
qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const
返回项目在指定step 值处的垂直剪切力。
另请参阅 setShearAt().
qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const
返回项目在指定step 值处的水平平移值。
另请参阅 setTranslationAt().
qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const
返回项目在指定step 值处的垂直平移值。
另请参阅 setTranslationAt().
© 2025 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.