本页面内容

lottietoqml

lottietoqml 是 Qt 随附的一个命令行工具,用于将 Lottie 文档转换为 QML 文件。该 QML 文件随后可作为组件用于Qt Quick 应用程序中。

您可以直接使用lottietoqml ,或通过 CMake 命令qt_target_qml_from_lottie进行调用。

有关如何在应用程序中使用lottietoqml 的演示,请参阅lottietoqml 示例。

概述

lottietoqml 工具将 Lottie 文件转换为使用Qt Quick 基元的 QML 文件。由于Qt Quick 具有硬件加速功能,因此渲染动画时的性能可能优于使用 Qt Lottie Animation。此外,Qt Quick 支持可缩放矢量图形(SVG),因此生成的控件将在技术允许的范围内实现平滑变换。

用法

lottietoqml 的基本用法是提供一个输入文件和一个输出文件:lottietoqml input.json output.qml 。这将读取input.json 文件,并将其转换为output.qml 中的对应Qt Quick 场景,该场景随后可作为Qt Quick 应用程序的一部分使用。

此外,它还支持以下选项:

选项描述
–copyright-statement <字符串>在生成的文件开头添加 <string> 作为注释。
-c, –curve-renderer启用曲线渲染器后端,用于 Qt Quick Shapes。这可在场景中实现平滑、抗锯齿的形状,且无需多采样,但会带来一定的额外开销。
-a,--asynchronous-shapes在生成的场景中,对所有Shape 元素启用asynchronous 模式。这可能会提高CPU利用率和响应速度。
-p, –optimize-paths在将路径写入 QML 文件之前启用路径优化,这可能会加快后续的加载和渲染速度。
–outline-stroke-mode对填充形状的轮廓(边界)进行描边,而非原始路径。
-t, –type-name <字符串>输出将使用类型名称 <string> 代替 `Shape`。这允许使用自定义项来覆盖 `Shape ` 项的默认行为。
-v, –view显示将生成的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.