
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
ThePropertyChanges element describes new property bindings or values for a state.More...
| Since: | Qt 4.7 |
PropertyChanges is used to define the property values or bindings in aState. This enables an item's property values to be changed when itchanges between states.
To create aPropertyChanges object, specify thetarget item whose properties are to be modified, and define the new property values or bindings. For example:
import QtQuick 1.0Item {id:containerwidth:300;height:300Rectangle {id:rectwidth:100;height:100color:"red"MouseArea {id:mouseAreaanchors.fill:parent }states:State {name:"resized";when:mouseArea.pressedPropertyChanges {target:rect;color:"blue";height:container.height } } }}
When the mouse is pressed, theRectangle changes to theresized state. In this state, thePropertyChanges object sets the rectangle's color to blue and theheight value to that ofcontainer.height.
Note this automatically bindsrect.height tocontainer.height in theresized state. If a property binding should not be established, and the height should just be set to the value ofcontainer.height at the time of the state change, set theexplicit property totrue.
APropertyChanges object can also override the default signal handler for an object to implement a signal handler specific to the new state:
PropertyChanges {target:myMouseAreaonClicked:doSomethingDifferent()}
Note:PropertyChanges can be used to change anchor margins, but not other anchor values; useAnchorChanges for this instead. Similarly, to change anItem'sparent value, use ParentChanges instead.
Theundefined value can be used to reset the property value for a state. In the following example, whentheText changes to thewiderText state, itswidth property is reset, giving the text its natural width and displaying the whole string on a single line.
Rectangle {width:300;height:200Text {id:myTextwidth:50wrapMode:Text.WordWraptext:"a text string that is longer than 50 pixels"states:State {name:"widerText"PropertyChanges {target:myText;width:undefined } } }MouseArea {anchors.fill:parentonClicked:myText.state="widerText" }}
WhenTransitions are used to animate state changes, they animate properties from their values in the current state to those defined in the new state (as defined byPropertyChanges objects). However, it is sometimes desirable to set a property valueimmediately during aTransition, without animation; in these cases, thePropertyAction element can be used to force an immediate property change.
See thePropertyAction documentation for more details.
See alsostates example, States, andQtDeclarative.
If explicit is set to true, any potential bindings will be interpreted as once-off assignments that occur when the state is entered.
In the following example, the addition of explicit preventsmyItem.width from being bound toparent.width. Instead, it is assigned the value ofparent.width at the time of the state change.
PropertyChanges {target:myItemexplicit:truewidth:parent.width}
By default, explicit is false.
This property holds whether the previous values should be restored when leaving the state.
The default value istrue. Setting this value tofalse creates a temporary state that has permanent effects on property values.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.