QAnimationGroup Class
QAnimationGroup 类是动画组的抽象基类。更多内容...
| 头文件: | #include <QAnimationGroup> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 继承自: | QAbstractAnimation |
| 继承自: |
- 所有成员列表(包括继承的成员)
- QAnimationGroup 是动画框架的一部分。
公共函数
| QAnimationGroup(QObject *parent = nullptr) | |
| virtual | ~QAnimationGroup() |
| void | addAnimation(QAbstractAnimation *animation) |
| QAbstractAnimation * | animationAt(int index) const |
| int | animationCount() const |
| void | clear() |
| int | indexOfAnimation(QAbstractAnimation *animation) const |
| void | insertAnimation(int index, QAbstractAnimation *animation) |
| void | removeAnimation(QAbstractAnimation *animation) |
| QAbstractAnimation * | takeAnimation(int index) |
重新实现的受保护函数
| virtual bool | event(QEvent *event) override |
详细说明
动画组是动画(QAbstractAnimation 的子类)的容器。一个动画组通常负责管理其动画的state ,即决定何时启动、停止、恢复和暂停动画。目前,Qt 提供了两个此类动画组:QParallelAnimationGroup 和QSequentialAnimationGroup 。详情请查阅其类描述。
由于 QAnimationGroup 继承自QAbstractAnimation ,因此您可以组合多个动画组,并轻松构建复杂的动画图。您可以通过QAbstractAnimation 查询其所属的动画组(使用group() 函数)。
要启动一个顶级动画组,只需调用QAbstractAnimation 中的start()函数即可。所谓顶级动画组,是指其本身未被包含在另一个组中的动画组。不支持直接启动子组,这可能会导致意外行为。
QAnimationGroup 提供了添加和检索动画的方法。此外,您可以通过调用removeAnimation() 移除动画,并通过调用clear() 清空动画组。您可以通过监听QEvent::ChildAdded 和QEvent::ChildRemoved 事件来跟踪动画组中动画的变化。
QAnimationGroup 会拥有其所管理的动画的所有权,并确保在动画组被删除时,这些动画也会被删除。
另请参阅 QAbstractAnimation 、QVariantAnimation 以及《动画框架》。
成员函数文档
QAnimationGroup::QAnimationGroup(QObject *parent = nullptr)
创建一个 QAnimationGroup。将 `parent ` 作为参数传递给 `QObject` 的构造函数。
[virtual noexcept] QAnimationGroup::~QAnimationGroup()
删除该动画组。同时,该操作还将删除该动画组中的所有动画。
void QAnimationGroup::addAnimation(QAbstractAnimation *animation)
将animation 添加到该组中。这将调用insertAnimation ,其中索引等于animationCount()。
注意:该组 将拥有该动画的所有权。
警告:此 方法不会检查动画循环。开发者有责任确保所添加的animation 不会直接或间接包含this 动画组。
另请参阅 removeAnimation()。
QAbstractAnimation *QAnimationGroup::animationAt(int index) const
返回指向该组中位于index 处的动画的指针。当需要访问特定动画时,此函数非常有用。index 的取值范围在0到animationCount() - 1之间。
另请参阅 animationCount() 和indexOfAnimation()。
int QAnimationGroup::animationCount() const
返回该组管理的动画数量。
另请参阅 indexOfAnimation()、addAnimation() 和animationAt()。
void QAnimationGroup::clear()
移除并删除该动画组中的所有动画,并将当前时间重置为 0。
另请参阅 addAnimation() 和removeAnimation()。
[override virtual protected] bool QAnimationGroup::event(QEvent *event)
重写了:QAbstractAnimation::event(QEvent *event)。
int QAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const
返回animation 的索引。该索引可作为参数传递给其他以索引为参数的函数。
另请参阅 insertAnimation()、animationAt() 和takeAnimation()。
void QAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation)
将animation 插入到位于index 的此动画组中。如果index 为0,则将动画插入到开头;如果index 为animationCount(),则将动画插入到结尾。
注意:该组 将拥有该动画的所有权。
警告:此 方法不会检查动画循环。开发者有责任确保添加的animation 不直接或间接包含this 动画组。
另请参阅 takeAnimation()、addAnimation()、indexOfAnimation() 和removeAnimation()。
void QAnimationGroup::removeAnimation(QAbstractAnimation *animation)
将animation 从该组中移除。animation 的所有权转移给调用者。
另请参阅 takeAnimation()、insertAnimation() 和addAnimation()。
QAbstractAnimation *QAnimationGroup::takeAnimation(int index)
返回位于index 处的动画,并将其从动画组中移除。
注意: 该动画的所有权将转移给调用方。
另请参阅 removeAnimation()、addAnimation()、insertAnimation() 和indexOfAnimation()。
© 2026 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.