qt_target_qml_from_lottie
根据 Lottie 文件生成 QML 代码。
该命令定义在Qt6 包的LottieTools 组件中,可按以下方式加载:
find_package(Qt6 REQUIRED COMPONENTS LottieTools)该命令于 Qt 6.11 版本中引入。
语法
qt_target_qml_from_lottie(target
[CURVE_RENDERER]
[ASYNCHRONOUS_SHAPES] # since Qt 6.12
[OPTIMIZE_PATHS]
[OUTLINE_STROKE_MODE]
[TYPE_NAME "MyShapeName"]
[COPYRIGHT_STATEMENT "Copyright © Company1"]
FILES file1.json [file2.json ...]
OUTPUTS File1.qml [File2.qml ...]
)ASYNCHRONOUS_SHAPES 选项自 Qt 6.12 起引入。
如果禁用了无版本命令,请改用 `qt6_target_qml_from_lottie() `。它支持与该命令相同的参数集。
示例:
qt_target_qml_from_lottie(applottietoqmlexample
CURVE_RENDERER
OPTIMIZE_PATHS
FILES
original/FingerprintIcon.json
original/GoogleIcons.json
original/HappyStar.json
original/HeartMedical.json
original/SurprisedBoy.json
original/USAMapWithOutlines.json
original/UserAuthentication.json
original/UserInteractionAnimation.json
original/UserInterface.json
OUTPUTS
generated/FingerprintIcon.qml
generated/GoogleIcons.qml
generated/HappyStar.qml
generated/HeartMedical.qml
generated/SurprisedBoy.qml
generated/USAMapWithOutlines.qml
generated/UserAuthentication.qml
generated/UserInteractionAnimation.qml
generated/UserInterface.qml
)说明
qt_target_qml_from_lottie() 会根据FILES 中列出的 Lottie 图像列表,生成用于运行lottietoqml的构建步骤。生成的文件名称应在OUTPUTS 中指定。该列表的长度必须与FILES 中的长度一致,且第一个元素对应FILES 中的第一个元素,依此类推。 在OUTPUTS 中提供的名称将作为 QML 类型的名称出现在模块中。这些类型随后可在应用程序代码中进行实例化。
生成的 QML 文件将被添加到target 中的 QML 模块中。您必须先使用qt_add_qml_module()为target 定义一个模块。
可选地,可以提供一个COPYRIGHT_STATEMENT 参数,将版权信息插入到生成的文件中。
注意: 在命令行中使用时,某些 字符必须进行转义,否则在某些平台上可能会出现构建错误。
TYPE_NAME 该参数也是可选的,可用于将生成文件中所有Shape 类型的实例替换为自定义类型。这对于对提供的 Lottie 文件中的所有形状进行通用自定义非常有用。TYPE_NAME 应引用target QML 模块中可用的 QML 类型。
选项CURVE_RENDERER 、ASYNCHRONOUS_SHAPES 、OPTIMIZE_PATHS 和OUTLINE_STROKE_MODE 分别对应lottietoqml中的--curve-renderer 、--asynchronous-shapes 、--optimize-paths 和--outline-stroke-mode 。
© 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.