PropertyAction QML Type

指定动画播放过程中的即时属性更改。更多

Import Statement: import QtQuick
Inherits:

Animation

属性

详细说明

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"
        }
    }
}

但是,在这段代码中,由于State 是在过渡结束时定义值的,因此直到动画结束 才会设置transformOrigin 。动画将以默认的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.

属性文档

properties : string

property : string

target : QtObject

targets : list<QtObject> [read-only]

这些属性决定了受此操作影响的项目及其属性。

关于在不同情况下如何解释这些属性的详细信息,请参阅corresponding PropertyAnimation 文档。

另请参阅 exclude


exclude : list<QtObject> [read-only]

此属性包含不应受此操作影响的对象。

另请参见 targets


value : var

该属性包含要在属性上设置的值。

如果PropertyAction 是在TransitionBehavior 中定义的,则该值默认为Transition 的结束状态中定义的值,或触发Behavior 的属性更改的值。


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