[Qt-qml] Default state
michael.brasser at nokia.com
michael.brasser at nokia.com
Thu Sep 2 03:19:25 CEST 2010
On 02/09/2010, at 2:11 AM, ext Frederik Gladhorn wrote:
> when creating states in a QML element, it gets a default state "".
> We were wondering which properties this state has and which of the properties
> will (not) be affected when switching into this state. The documentation about
> this is currently not very clear.
The base state is effectively the state of the element when no explicit states have been applied. Take the following as an example:
Rectangle {
id: myRect
width: 100
height: 100
color: "green"
states: [
State {
name: "state1"
PropertyChanges {
target: myRect
color: "red"
}
},
State {
name: "state2"
PropertyChanges {
target: myRect
width: 200
}
}
]
}
In the above, we don't ever directly store any information about the base state. Instead, when we enter state1, we remember that in order to "rewind" it, we need to set the color back to green. Likewise, if we were to enter state2, we would remember that to rewind state2, we need to set the width back to 100. Going to the base state is then a matter of rewinding any changes made by the explicit states. Does that help clarify?
> Another question is what happens when one defines a new state "". Does this
> overwrite the default state?
It effectively adds a set of additional changes to apply when changing from another state back to "".
> Is this the state I end up in when passing
> state="somestring" where somestring is not a state identifier?
Doing this rewinds any explicit state changes, but doesn't apply anything that was specified in the explicit "" state.
The above describes what we do today, but I'm not sure that its correct/by design.
What are you trying to accomplish? You can create an effective named base state by doing something like:
Rectangle {
states: State {
name: "default"
...
}
state: "default"
}
and then always using default rather than "".
Regards,
Michael
More information about the Qt-qml
mailing list