QML State ElementThe State element defines configurations of objects and properties. More... This element was introduced in Qt 4.7. PropertiesDetailed DescriptionA state is a set of batched changes from the default configuration. All items have a default state that defines the default configuration of objects and property values. New states can be defined by adding State items to the states property to allow items to switch between different configurations. These configurations can, for example, be used to apply different sets of property values or execute different scripts. The following example displays a single Rectangle. In the default state, the rectangle is colored black. In the "clicked" state, a PropertyChanges element changes the rectangle's color to red. Clicking within the MouseArea toggles the rectangle's state between the default state and the "clicked" state, thus toggling the color of the rectangle between black and red. import QtQuick 1.0 Rectangle { id: myRect width: 100; height: 100 color: "black" MouseArea { id: mouseArea anchors.fill: parent onClicked: myRect.state == 'clicked' ? myRect.state = "" : myRect.state = 'clicked'; } states: [ State { name: "clicked" PropertyChanges { target: myRect; color: "red" } } ] } Notice the default state is referred to using an empty string (""). States are commonly used together with Transitions to provide animations when state changes occur. Note: Setting the state of an object from within another state of the same object is not allowed. See also states example, States, Transitions, and QtDeclarative. Property DocumentationThis property holds the changes to apply for this state By default these changes are applied against the default state. If the state extends another state, then the changes are applied against the state being extended. This property holds the state that this state extends. When a state extends another state, it inherits all the changes of that state. The state being extended is treated as the base state in regards to the changes specified by the extending state. This property holds the name of the state. Each state should have a unique name within its item. This property holds when the state should be applied. This should be set to an expression that evaluates to true when you want the state to be applied. For example, the following Rectangle changes in and out of the "hidden" state when the MouseArea is pressed: Rectangle { id: myRect width: 100; height: 100 color: "red" MouseArea { id: mouseArea; anchors.fill: parent } states: State { name: "hidden"; when: mouseArea.pressed PropertyChanges { target: myRect; opacity: 0 } } } If multiple states in a group have when clauses that evaluate to true at the same time, the first matching state will be applied. For example, in the following snippet state1 will always be selected rather than state2 when sharedCondition becomes true. Item { states: [ State { name: "state1"; when: sharedCondition }, State { name: "state2"; when: sharedCondition } ] // ... } © 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Privacy Policy Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. |