The HistoryState type provides a means of returning to a previously active substate. 更多...
导入语句: | import QtQml.StateMachine 6.2 |
Since: | Qt 5.4 |
继承: | QAbstractState |
A history state is a pseudo-state that represents the child state that the parent state was in the last time the parent state was exited. A transition with a history state as its target is in fact a transition to one of the other child states of the parent state. HistoryState is part of Qt State Machine QML API .
使用 defaultState property to set the state that should be entered if the parent state has never been entered.
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 } } } } }
By default, a history state is shallow, meaning that it will not remember nested states. This can be configured through the historyType 特性。
另请参阅 StateMachine and State .
defaultState : QAbstractState |
The default state of this history state.
The default state indicates the state to transition to if the parent state has never been entered before.
historyType : enumeration |
The type of history that this history state records.
此特性的默认值为 HistoryState .ShallowHistory.
This enum specifies the type of history that a HistoryState records.