Is there a way to tell if an Item is running a State Transition?
-
I don't understand why this doesn't work. When clicking, I expected the text to change to "Running: true". I want to know when an Item is in transition so I can chain together multiple states. i.e. go to state1, <signal>, go to state2.
qmlviewer -sizeviewtorootobject trans.qml
@
import Qt 4.7Rectangle {
id: root
property bool inTransition: trans1.runningwidth: 640 height: 480 Text { anchors.centerIn: parent font.pixelSize: 32 text: "Running: " + inTransition } MouseArea { anchors.fill: parent onClicked: { if(root.state == "big") { root.state = "" } else { root.state = "big" } } } states: [ State { name: "big" PropertyChanges { target: root width: 800 height: 600 } } ] transitions: [ Transition { id: trans1 property bool running: anim1.running || anim2.running PropertyAnimation { id: anim1; properties: "width"; duration: 2000 } PropertyAnimation { id: anim2; properties: "height"; duration: 3000 } } ]
}
@ -
Hi,
It isn't currently possible to tell when an animation in a transition is running, see http://bugreports.qt.nokia.com/browse/QTBUG-13927.
For a simple example like the above, you could add a ScriptAction to the end of the transition that would fire a signal or set the new state. There is also an (undocumented, so I'm unsure whether its officially supported) onCompleted signal handler in the State element, that fires once the transition is complete, and the state is fully entered.
Regards,
Michael -
Hi Michael,
Thanks for the suggestion! Here's a working example based on the information you provided. I'm trying to create a new Item called SmartTransition to encapsulate the ScriptAction and property setting. I'll post it if I figure something out.
@
import Qt 4.7Rectangle {
id: root
property bool inTransition: trans1.inTransition
width: 640
height: 480Text { anchors.centerIn: parent font.pixelSize: 32 text: "Running: " + inTransition } MouseArea { anchors.fill: parent onClicked: { if(root.state == "big") { root.state = "" } else { root.state = "big" } } } states: [ State { name: "big" PropertyChanges { target: root width: 800 height: 600 } } ] transitions: [ Transition { id: trans1 property bool inTransition: false SequentialAnimation { ScriptAction { script: { inTransition = true } } ParallelAnimation { PropertyAnimation { properties: "width"; duration: 2000 } PropertyAnimation { properties: "height"; duration: 3000 } } ScriptAction { script: { inTransition = false } } } } ]
}
@