在本页

OpacityAnimator QML Type

OpacityAnimator 类型用于动画显示项目的不透明度。更多

Import Statement: import QtQuick
Inherits:

Animator

详细说明

Animator 类型不同于普通的动画类型。使用 Animator 时,动画可以在呈现线程中运行,而属性值将在动画完成后跳转到末尾。

Item::opacity 的值会在动画结束后更新。

以下代码段展示了如何将 OpacityAnimator 与矩形项结合使用。

Rectangle {
    id: opacityBox
    width: 50
    height: 50
    color: "lightsteelblue"
    OpacityAnimator {
        target: opacityBox;
        from: 0;
        to: 1;
        duration: 1000
        running: true
    }
}

也可以使用on 关键字将 OpacityAnimator 直接绑定到项目实例上。

Rectangle {
    width: 50
    height: 50
    color: "lightsteelblue"
    OpacityAnimator on opacity{
        from: 0;
        to: 1;
        duration: 1000
    }
}

注: 在使用非线程渲染循环时,动画类型没有任何益处。

注: 建议应用程序考虑基于多线程、异步原则的设计,而不是依靠 Animator 来显示动画内容,同时在主(GUI)线程上执行昂贵的阻塞工作。在 QML 中使用WorkerScriptasynchronous image loading ,在 C++ 中使用工作线程、并行算法,而不是冗长的阻塞操作、 Qt Concurrent和 C++ 中的例程,从而使整个应用程序和用户界面始终保持响应。

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