Is it possible to define another set of states in the same qml file
-
I wanted to define two different states for two different components in the same qml file
Example :
Text { id : text }
Button { id : button }
// states for the text filed
states: [
State {
name: "charging"
PropertyChanges {
target: text
text: "charging"
}
},
State{
name: "discharging"
PropertyChanges {
target: text
text: "discharging"
}
}
]// states for the button
states: [
State {
name: "pressed"
PropertyChanges {
target: button
color: "read"
}
},
State{
name: "released"
PropertyChanges {
target: button
text: "black"
}
}
]// wanted to assign states to text and button component
text.state = "charging"
button.state = "pressed"Note : text and button state update will be asynchronous.
Want to the correct way to assign states to text and buttons ? -
Define the states in each object.
Text { id: text states: [ State { name: "charging" ... }, ... ] } Button { id: button states: [ State { name: "pressed" ... }, ... ] }
Also please encase your code in triple backticks ``` for multiline blocks and single backtick ` for inline snippets.