Qt Lottie Animation
Qt Lottie Animation提供 QML API,用于渲染 Lottie 格式文件中的图形和动画。这些文件通常是从 Adobe After Effects 的Lottie插件导出的。
LottieAnimation 项目使用QPainter软件渲染器将动画渲染到中间缓冲区。这可能会对插图的大小和目标硬件的性能造成一些限制。作为一种替代方法,程序中包含了一个名为lottietoqml 的工具。该工具可将 Lottie 动画转换为 QML。因此,它们可以使用Qt Quick 中的硬件加速渲染器进行渲染。
如果在编译时已知 Lottie 文件,也可以使用lottietoqml工具或封装了该工具的qt_target_qml_from_lottieCMake 命令将其转换为 QML。
最后,VectorImage Qt Quick 项目可以直接加载 Lottie 格式文件。它在运行时使用插件中的 lottietoqml 功能将它们转换为 QML。
开始使用
使用以下语句导入类型:
import Qt.labs.lottieqt
限制
实施遵循lottie 的主规范。如果发现导出的 Lottie 文件与规范有偏差,我们会尽可能加以考虑。
一般限制
- 不支持表达式
- 时间轴只支持帧模式,不支持时间模式
警告: Qt Lottie Animation 的输入文件被假定为可信内容。建议应用程序开发人员切勿从不可信的来源输入数据。
动画级别限制
不支持以下属性:
assets- 可重复使用的文本和图像chars文本
图层
不支持以下属性
ao(自动调整方向)bm(混合模式)maskProperties遮罩sr(时间拉伸)
形状
不支持一些较少使用的元素和形状,包括
gstroke(渐变描边)元素- 嵌套的中继器形状
还需注意的是,使用多个活动修剪路径(例如嵌套组中的修剪路径)时的行为是不可预测的。
效果
唯一支持的效果是Slide 和Layer Fill 。
示例
- qtlottieviewer 示例演示了如何在Qt Quick 应用程序中使用LottieAnimation 项目加载、显示和控制 Lottie 文件。
- lottietoqml 示例演示了如何使用lottietoqml工具将 Lottie 文件转换为Qt Quick 场景并加载到应用程序中。
许可证
Qt Lottie Animation Lottie 是由Qt 公司根据商业许可提供的。此外,它还受GNU 通用公共许可证第 3 版的保护。更多详情,请参阅Qt Licensing。
参考资料
相关信息
© 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.