Home · All Classes · All Functions · Overviews

QML PropertyChanges Element Reference

The PropertyChanges element describes new property values for a state. More...

Properties

Detailed Description

PropertyChanges provides a state change that modifies the properties of an item.

Here is a property change that modifies the text and color of a Text element when it is clicked:

 Text {
     id: myText
     width: 100; height: 100
     text: "Hello"
     color: "blue"

     states: State {
         name: "myState"

         PropertyChanges {
             target: myText
             text: "Goodbye"
             color: "red"
         }
     }

     MouseArea { anchors.fill: parent; onClicked: myText.state = 'myState' }
 }

State-specific script for signal handlers can also be specified:

 PropertyChanges {
     target: myMouseArea
     onClicked: doSomethingDifferent()
 }

You can reset a property in a state change by assigning undefined. In the following example we reset theText's width when we enter state1. This will give the text its natural width (which is the whole string on one line).

 import Qt 4.6

 Rectangle {
     width: 640
     height: 480
     Text {
         id: theText
         width: 50
         wrap: true
         text: "a text string that is longer than 50 pixels"
     }

     states: State {
         name: "state1"
         PropertyChanges {
             target: theText
             width: undefined
         }
     }
 }

Changes to an Item's parent or anchors should be done using the associated change elements (ParentChange and AnchorChanges, respectively) rather than PropertyChanges.

See also States.


Property Documentation

explicit : bool

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 prevents myItem.width from being bound to parent.width. Instead, it is assigned the value of parent.width at the time of the state change.

 PropertyChanges {
     target: myItem
     explicit: true
     width: parent.width
 }

By default, explicit is false.


restoreEntryValues : bool

Whether or not the previous values should be restored when leaving the state. By default, restoreEntryValues is true.

By setting restoreEntryValues to false, you can create a temporary state that has permanent effects on property values.


target : Object

This property holds the object which contains the properties to be changed.



Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.7.0