PropertyAction QML Type
指定动画过程中属性即时的变化。更多...
| Import Statement: | import QtQuick |
| Inherits: |
属性
- exclude : list<QtObject>
- properties : string
- property : string
- target : QtObject
- targets : list<QtObject>
- value : var
详细说明
PropertyAction 用于指定在动画过程中立即更改属性。该属性更改不会进行动画处理。
该属性在动画过程中用于设置非动画化的属性值。
例如,以下是一个SequentialAnimation ,它将图像的opacity 属性设置为.5 ,对图像宽度进行动画处理,然后将opacity 重新设置为1 :
SequentialAnimation {
PropertyAction { target: img; property: "opacity"; value: .5 }
NumberAnimation { target: img; property: "width"; to: 300; duration: 1000 }
PropertyAction { target: img; property: "opacity"; value: 1 }
}PropertyAction 对于在Transition 期间精确控制属性变更的时机也非常有用。例如,如果要在State 中使用PropertyChanges 让项目围绕特定的transformOrigin 旋转,可以像这样实现:
Item {
width: 400; height: 400
Rectangle {
id: rect
width: 200; height: 100
color: "red"
states: State {
name: "rotated"
PropertyChanges { target: rect; rotation: 180; transformOrigin: Item.BottomRight }
}
transitions: Transition {
RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
}
MouseArea {
anchors.fill: parent
onClicked: rect.state = "rotated"
}
}
}然而,使用此代码时,transformOrigin 直到动画结束后才会被设置,因为State 被用于定义过渡结束时的值。动画将先围绕默认的transformOrigin 旋转,然后跳转至Item.BottomRight 。要解决此问题,请在RotationAnimation 开始之前插入一个 PropertyAction:
transitions: Transition {
SequentialAnimation {
PropertyAction { target: rect; property: "transformOrigin" }
RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
}
}这会立即将transformOrigin 属性设置为Transition 结束状态中定义的值(即PropertyAction对象中定义的值),从而确保旋转动画以正确的变换原点开始。
另请参阅 《Qt Quick 中的动画与过渡》以及 Qt Qml。
属性文档
exclude : list<QtObject> [read-only]
该属性用于存储不应受此操作影响的对象。
另请参阅 targets 。
这些属性决定了受此操作影响的项目及其属性。
关于这些属性在不同情况下如何被解释的详细信息,请参阅corresponding PropertyAnimation 中的文档。
另请参阅 exclude 。
value : var
该属性存储要设置到该属性的值。
如果PropertyAction 在Transition 或Behavior 内被定义,则该值默认为Transition 的结束状态中定义的值,或者触发Behavior 的属性变更值。
© 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.