我有几种状态,我只用它来改变一些属性:
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)
}
由于someProperty
的不同状态可能具有相同的值,因此我无法依赖somePropertyChange
信号,但我甚至无法依赖onStateChange
(如示例中所示) )因为它运行时属性不变。
那么每次状态改变时我怎么能运行doSomething()
?使用QML
?
答案 0 :(得分:1)
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)
}
}
]
}