HistoryState QML Type
HistoryState 类型提供了返回先前活动子状态的方法。更多
Import Statement: | import QtQml.StateMachine 6.9 |
Inherits: |
属性
- defaultState : QAbstractState
- historyType : enumeration
详细说明
历史状态是一种伪状态,代表父状态最后一次退出时的子状态。以历史状态为目标的转换实际上是向父状态的其他子状态的转换。HistoryState 是Qt State Machine QML API 的一部分。
使用defaultState 属性可设置从未进入父状态时应进入的状态。
使用示例
import QtQuick import QtQml.StateMachine as DSM Rectangle { Button { anchors.fill: parent id: button text: "Press me" DSM.StateMachine { id: stateMachine initialState: parentState running: true DSM.State { id: parentState initialState: child2 onEntered: console.log("parentState entered") onExited: console.log("parentState exited") DSM.State { id: child1 onEntered: console.log("child1 entered") onExited: console.log("child1 exited") } DSM.State { id: child2 onEntered: console.log("child2 entered") onExited: console.log("child2 exited") } DSM.HistoryState { id: historyState defaultState: child1 } DSM.SignalTransition { targetState: historyState // Clicking the button will cause the state machine to enter the child state // that parentState was in the last time parentState was exited, or the history state's default // state if parentState has never been entered. signal: button.clicked } } } } }
默认情况下,历史状态是浅层状态,即不会记住嵌套状态。这可以通过historyType 属性进行配置。
另请参阅 StateMachine 和State 。
属性文档
defaultState : QAbstractState |
此历史状态的默认状态。
默认状态表示如果从未进入过父状态,则要过渡到的状态。
historyType : enumeration |
该历史状态记录的历史类型。
此属性的默认值是HistoryState.ShallowHistory。
该枚举指定了HistoryState 记录的历史类型。
- HistoryState.ShallowHistory 只记录父状态的直接子状态。在这种情况下,以历史状态为目标的转换将以父状态最后一次退出时的直接子状态结束。这是默认情况。
- HistoryState.DeepHistory 会记录嵌套状态。在这种情况下,以历史状态为目标的过渡将在父级上次退出时所处的嵌套最深的子级状态中结束。
© 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.