Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QML PropertyChanges Element

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

This element was introduced in Qt 4.7.

Properties

Detailed Description

PropertyChanges is used to define the property values or bindings in a State. This enables an item's property values to be changed when it changes between states.

To create a PropertyChanges object, specify the target item whose properties are to be modified, and define the new property values or bindings. For example:

 import QtQuick 1.0

 Item {
     id: container
     width: 300; height: 300

     Rectangle {
         id: rect
         width: 100; height: 100
         color: "red"

         MouseArea {
            id: mouseArea
            anchors.fill: parent
         }

         states: State {
            name: "resized"; when: mouseArea.pressed
            PropertyChanges { target: rect; color: "blue"; height: container.height }
         }
     }
 }

When the mouse is pressed, the Rectangle changes to the resized state. In this state, the PropertyChanges object sets the rectangle's color to blue and the height value to that of container.height.

Note this automatically binds rect.height to container.height in the resized state. If a property binding should not be established, and the height should just be set to the value of container.height at the time of the state change, set the explicit property to true.

A PropertyChanges object can also override the default signal handler for an object to implement a signal handler specific to the new state:

 PropertyChanges {
     target: myMouseArea
     onClicked: doSomethingDifferent()
 }

Note: PropertyChanges can be used to change anchor margins, but not other anchor values; use AnchorChanges for this instead. Similarly, to change an Item's parent value, use ParentChanges instead.

Resetting property values

The undefined value can be used to reset the property value for a state. In the following example, when theText changes to the widerText state, its width property is reset, giving the text its natural width and displaying the whole string on a single line.

 Rectangle {
     width: 300; height: 200

     Text {
         id: myText
         width: 50
         wrapMode: Text.WordWrap
         text: "a text string that is longer than 50 pixels"

         states: State {
             name: "widerText"
             PropertyChanges { target: myText; width: undefined }
         }
     }

     MouseArea {
         anchors.fill: parent
         onClicked: myText.state = "widerText"
     }
 }

Immediate property changes in transitions

When Transitions 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 by PropertyChanges objects). However, it is sometimes desirable to set a property value immediately during a Transition, without animation; in these cases, the PropertyAction element can be used to force an immediate property change.

See the PropertyAction documentation for more details.

See also states example, States, and QtDeclarative.

Property Documentation

read-onlyexplicit : 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

This property holds whether the previous values should be restored when leaving the state.

The default value is true. Setting this value to false creates a temporary state that has permanent effects on property values.


target : Object

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


Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année

Le Qt Labs au hasard

Logo

QLocale : à propos du temps (et des dates, et des langues, et des...)

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web