本页内容

StateGroup QML Type

为非Item类型提供内置状态支持。更多内容...

Import Statement: import QtQuick

属性

详细说明

Item(及其所有派生类型)通过其state 、states 和transitions 属性,为状态和转换提供了内置支持。StateGroup提供了一种简便的方法,可在其他(非从Item派生)类型中使用此支持。

MyCustomObject {
    StateGroup {
        id: myStateGroup
        states: State {
            name: "state1"
            // ...
        }
        transitions: Transition {
            // ...
        }
    }

    onSomethingHappened: myStateGroup.state = "state1";
}

另请参阅 Qt Quick 中的“状态”、“转换”以及 Qt Qml。

属性文档

state : string

该属性保存状态组当前状态的名称。

该属性常用于脚本中以在不同状态之间切换。例如:

function toggle() {
    if (button.state == 'On')
        button.state = 'Off';
    else
        button.state = 'On';
}

如果状态组处于其基础状态(即未显式设置任何状态),则 `state ` 将为空字符串。同样,您可以通过将状态组的当前状态设置为 `''` 来将其恢复为基础状态。

另请参阅 《Qt Quick 状态》。

states : list<State> [read-only]

该属性保存由状态组定义的状态列表。

StateGroup {
    states: [
        State {
            // State definition...
        },
        State {
            // ...
        }
        // Other states...
    ]
}

另请参阅 Qt Quick 状态。

transitions : list<Transition> [read-only]

该属性保存了由状态组定义的过渡列表。

StateGroup {
    transitions: [
        Transition {
          // ...
        },
        Transition {
          // ...
        }
        // ...
    ]
}

另请参阅 “过渡”。

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