ColorAnimation QML Type

动画显示颜色值的变化。更多

Import Statement: import QtQuick
Inherits:

PropertyAnimation

属性

详细说明

ColorAnimation 是一个专门的PropertyAnimation ,用于定义颜色值变化时应用的动画。

以下是应用于Rectanglecolor 属性的 ColorAnimation,作为属性值源。它使color 属性的值在 1000 毫秒内从当前值变为 "红色":

import QtQuick

Rectangle {
    width: 100; height: 100
    color: "red"

    ColorAnimation on color { to: "yellow"; duration: 1000 }
}

与其他动画类型一样,ColorAnimation 可以多种方式应用,包括过渡、行为和属性值源。 Qt Quick 文档 中的动画和过渡显示了多种创建动画的方法。

为方便起见,当在Transition 中使用 ColorAnimation 时,它将对任何在状态变化期间被修改的color 属性进行动画处理。如果为动画明确设置了propertyproperties ,则将使用这些属性代替动画。

另请参阅 Qt QuickQt Quick 示例 - 动画中的动画和过渡

属性文档

from : color

该属性用于保存动画开始时的颜色值。

例如,在颜色值达到 "#c0c0c0 "之前,不会应用以下动画:

Item {
    states: [
        // States are defined here...
    ]

    transitions: Transition {
        ColorAnimation { from: "#c0c0c0"; duration: 2000 }
    }
}

如果ColorAnimation 定义在TransitionBehavior 中,则该值默认为Transition 的起始状态中定义的值,或Behavior 被触发时该属性的当前值。

另请参阅 Qt Quick 中的动画和过渡


to : color

该属性保存动画结束时的颜色值。

如果ColorAnimation 定义在TransitionBehavior 中,则该值默认为Transition 的结束状态中定义的值,或触发Behavior 的属性变化值。

另请参阅 Qt Quick 中的动画和过渡


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