本页内容

UniformAnimator QML Type

UniformAnimator 类型用于对 `ShaderEffect` 的统一属性进行动画处理。更多内容...

Import Statement: import QtQuick
Inherits:

Animator

属性

详细说明

Animator 这些类型与普通的动画类型不同。使用 Animator 时,动画可在渲染线程中运行,且动画完成后属性值将跳转至终点。

定义均匀变量的 QML 属性的值会在动画结束后更新。

以下代码片段展示了如何将 UniformAnimator 与ShaderEffect 项结合使用。

ShaderEffect {
    id: shader
    width: 50
    height: 50
    property variant t;
    UniformAnimator {
        target: shader
        uniform: "t"
        from: 0
        to: 1
        duration: 1000
        running: true
    }
    fragmentShader: "qrc:shader.frag.qsb"
}

也可以使用 `on ` 关键字将 `UniformAnimator` 直接绑定到 `ShaderEffect ` 实例的统一属性上。

ShaderEffect {
    width: 50
    height: 50
    property variant t;
    UniformAnimator on t {
        from: 0
        to: 1
        duration: 1000
    }
    fragmentShader: "qrc:shader.frag.qsb"
}

注意: 当使用非多线程渲染循环时,Animator 类型没有任何优势。

注意:建议 应用程序采用基于多线程、异步原则的设计,而不是依赖 Animator 在主(GUI)线程上执行耗时且阻塞的操作时显示动画内容。与其进行长时间的阻塞操作,不如优先在 QML 中使用WorkerScript 和asynchronous image loading ,以及 C++ 中的工作线程、并行算法 Qt Concurrent以及 C++ 中的协程,从而确保整个应用程序和用户界面始终保持响应。

另请参阅 ShaderEffect 和ShaderEffectSource 。

属性文档

uniform : string

该属性存储要进行动画处理的统一名称。

该统一变量的值必须与目标ShaderEffect 上的某个属性相对应,并且必须是片段着色器或顶点着色器中类型为float 的统一变量。

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