ColorAnimation QML Type
对颜色值的变化进行动画处理。更多...
| Import Statement: | import QtQuick |
| Inherits: |
属性
详细说明
ColorAnimation 是一种专门的PropertyAnimation ,用于定义在颜色值发生变化时应用的动画效果。
以下示例将 ColorAnimation 应用于Rectangle 的color 属性,作为属性值来源。它将color 属性的值从当前值动画过渡到“red”,耗时 1000 毫秒:
import QtQuick
Rectangle {
width: 100; height: 100
color: "red"
ColorAnimation on color { to: "yellow"; duration: 1000 }
}与其他动画类型一样,ColorAnimation可以通过多种方式应用,包括过渡、行为和属性值源。 Qt Quick 文档中的“动画和过渡”部分展示了创建动画的多种方法。
为方便起见,当在Transition 中使用ColorAnimation时,它会动画化状态变化过程中被修改的任何color 属性。如果为动画显式设置了property 或properties ,则将使用这些属性。
另请参阅 《Qt Quick 》中的“动画与过渡”以及《Qt Quick 示例——动画》。
属性文档
from : color
该属性用于指定动画应开始时的颜色值。
例如,在颜色值达到“#c0c0c0”之前,以下动画不会生效:
Item {
states: [
// States are defined here...
]
transitions: Transition {
ColorAnimation { from: "#c0c0c0"; duration: 2000 }
}
}如果 `ColorAnimation ` 在 `Transition ` 或 `Behavior` 中定义,则该值默认为 `Transition` 的起始状态中定义的值,或者 `Behavior ` 被触发时该属性的当前值。
另请参阅 Qt Quick 中的“动画与过渡”。
to : color
该属性存储动画应结束时的颜色值。
如果“ColorAnimation ”是在“Transition ”或“Behavior ”中定义的,则该值默认为“Transition ”的结束状态中定义的值,或者触发“Behavior ”的属性“change”的值。
另请参阅 Qt Quick 中的“动画与过渡”。
© 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.