场景图 - 多线程动画
展示了在使用Qt Quick 的多线程渲染循环时,自定义项如何独立于主线程进行动画播放的优势。

本示例通过实现一个自定义项,展示了Animator 类型背后的基本概念——该项不依赖于主线程驱动的标准Qt Quick 动画框架,从而能够有效地自行进行动画播放。
在正常情况下,左右两个旋转图标的行为应完全一致。然而,一旦示例通过执行某些耗时操作阻塞了主线程,就会明显发现左侧旋转图标的动画不再流畅。
注意:本示例 应使用Qt Quick 的threaded 渲染循环运行。在大多数情况下,这是默认设置。使用basic 渲染循环并无积极效果,因为该循环中的一切操作(包括所有渲染)均在主线程上进行。
未实现自定义QQuickItem 的应用程序可通过使用Animator 中的类型(例如 QML 中的XAnimator 或OpacityAnimator )获得相同的好处。而在构建自定义项时,遵循本示例的实现方式即可获得类似效果。
另请参阅 Qt Quick 场景图。
© 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.