场景图 - 线程动画

展示了自定义项在使用Qt Quick 的线程渲染循环时独立于主线程进行动画的好处。

本示例展示了Animator 类型背后的基本概念,通过实现一个自定义项目,该项目不依赖于主线程驱动的标准Qt Quick 动画框架,可以有效地实现自身动画。

在正常情况下,左右两个旋转器的行为应该是相同的。但是,一旦示例通过执行一些繁重的操作阻塞了主线程,就会发现左侧旋转器的动画不再流畅。

注意: 本例应在threaded render loop ofQt Quick 下运行。在大多数情况下,这是默认设置。使用basic 渲染循环不会产生任何积极影响,因为包括所有渲染在内的一切操作都是在主线程上进行的。

没有自定义QQuickItem 实现的应用程序可以通过使用Animator 类型(如 QML 中的XAnimatorOpacityAnimator )获得同样的好处。而在构建自定义项目时,按照示例的实现方法也能获得类似的效果。

示例项目 @ code.qt.io

另请参阅 Qt Quick 场景图

© 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.