Change states.
-
Hello all!
- How can I find out the values of previous state, then state changes?
- How to run some script then get out from some state? (analogue of StateChangeScript{}, but run on exit state)
Example:
@
Rectangle{
id: myrect
states:[
state1{name: "state1"; target: myrect; color: "Red"},
state2{name: "state2"; target: myrect; color: "Green"},
state3{name: "state3"; target: myrect; color: "Blue"},
...
state10{name: "state10"; target: myrect; color: "Black"},
]
onStateChange:{
console.log( ) // this is trouble. I need print "color changed from Green to Yello"
}
}
@my Qt version is 4.8. QML 1.1.
sory for bad English. -
Hello,
a quick option to remember a state name is to introduce "a string property to which you would assign":http://qt-project.org/doc/qt-4.8/propertybinding.html a name of the current state on every state change.
To get the "value" of the previous state, you need to do state name comparisons.As for running scripts, you need to specify what would the next state be. QML elements cannot be stateless (they at least have their default state).
-
Thanks for reply!
-
I know this method, but he is bulky. Probably, have to do so..
-
I not may spesify next state. But i need to run script then go out some state.
may optionally be another method, without states?
my real goal is "container" element without Loader:
@
MyPage.qml:
Rectangle{
//some code
visible: false
property variant myExitFunc
}
@
MyContainer.qml:
@
Item{
MyPage{id: r1; myExitFunc: {/code/}}
MyPage{id: r2; myExitFunc: {/code/}}
...
MyPage{id: r10; myExitFunc: {/code/}}states:{ State{ name:page1 PropertyChanges:{ target: r1 visible: true }}
....
State{ name:page1
PropertyChanges:{
target: r10
visible: true
}}
}
}
@
And i not may use onVisibleChanged beacouse MyContainer may be unvisible (Which implies, that myExitFuncshould run 10 times then MyContainer.visible = true).UPD: fix error in source code
-
-
I am not sure if we understand each other. Every QML element has to have a state. You cannot "go out of state". If you want to implement such a page stack, you need to make the other pages invisible in the state change definition.