I have several states which I use only to change some properties:
Item {
id: props
property int someProperty: 0
// ...
states: [
State {
name: "firstState"
PropertyChange {
target: props
someProperty: 1
// ...
}
},
State {
name: "secondState"
PropertyChange {
target: props
someProperty: 1
// ...
}
}
]
onStateChange: doSomething(someProperty)
}
Since different states could have the same value for someProperty
I can't rely on the somePropertyChange
signal, but I can't even rely on the onStateChange
(as in the example) since when it runs the properties are unchanged.
So how could I run doSomething()
every time the state change? There is a better way to do this kind of things with QML
?
You can run some script using StateChangeScript.
Item {
id: props
property int someProperty: 0
states: [
State {
name: "firstState"
PropertyChanges {
target: props
someProperty: 1
}
StateChangeScript {
name: "firstScript"
script: console.log("entering first state")
}
},
State {
name: "secondState"
PropertyChanges {
target: props
someProperty: 1
}
StateChangeScript {
name: "secondScript"
script: console.log("entering second state")
}
}
]
}
Item {
id: props
property int someProperty: 0
// ...
states: [
State {
name: "firstState"
PropertyChange {
target: props
someProperty: 1
// ...
}
},
State {
name: "secondState"
PropertyChange {
target: props
someProperty: 1
// ...
}
}
]
transitions: [
Transition {
ScriptAction {
script: console.log("transition to " + props.state)
}
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With