在此页面上

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]
                          [OPTIMIZE_PATHS]
                          [OUTLINE_STROKE_MODE]
                          [TYPE_NAME "MyShapeName"]
                          [COPYRIGHT_STATEMENT "Copyright © Company1"]
                          FILES file1.json [file2.json ...]
                          OUTPUTS File1.qml [File2.qml ...]
                          )

如果禁用了无版本命令,请使用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_RENDEREROPTIMIZE_PATHSOUTLINE_STROKE_MODE 分别对应于lottietoqml中的--curve-renderer--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.