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 Transition Element

The Transition element defines animated transitions that occur on state changes. More...

This element was introduced in Qt 4.7.

Properties

Detailed Description

A Transition defines the animations to be applied when a State change occurs.

For example, the following Rectangle has two states: the default state, and an added "moved" state. In the "moved state, the rectangle's position changes to (50, 50). The added Transition specifies that when the rectangle changes between the default and the "moved" state, any changes to the x and y properties should be animated, using an Easing.InOutQuad.

 import QtQuick 1.0

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

     MouseArea {
         id: mouseArea
         anchors.fill: parent
     }

     states: State {
         name: "moved"; when: mouseArea.pressed
         PropertyChanges { target: rect; x: 50; y: 50 }
     }

     transitions: Transition {
         NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
     }
 }

Notice the example does not require to and from values for the NumberAnimation. As a convenience, these properties are automatically set to the values of x and y before and after the state change; the from values are provided by the current values of x and y, and the to values are provided by the PropertyChanges object. If you wish, you can provide to and from values anyway to override the default values.

By default, a Transition's animations are applied for any state change in the parent item. The Transition from and to values can be set to restrict the animations to only be applied when changing from one particular state to another.

To define multiple transitions, specify Item::transitions as a list:

 transitions: [
   Transition {
       from: "stop"; to: "go"
       PropertyAnimation { target: stopLight
                           properties: "color"; duration: 1000 }
   },
   Transition {
       from: "go"; to: "stop"
       PropertyAnimation { target: goLight
                           properties: "color"; duration: 1000 }
   } ]

If multiple Transitions are specified, only a single (best-matching) Transition will be applied for any particular state change. In the example above, when changing to state1, the first transition will be used, rather than the more generic second transition.

If a state change has a Transition that matches the same property as a Behavior, the Transition animation overrides the Behavior for that state change.

See also QML Animation and Transitions, states example, States, and QtDeclarative.

Property Documentation

read-onlydefaultanimations : list<Animation>

This property holds a list of the animations to be run for this transition.

 transitions: Transition {
     PropertyAnimation { duration: 3000 }
     ColorAnimation { duration: 3000 }
 }

The top-level animations are run in parallel. To run them sequentially, define them within a SequentialAnimation:

 transitions: Transition {
     SequentialAnimation {
         PropertyAnimation { property: "x"; duration: 1000 }
         ColorAnimation { duration: 1000 }
     }
 }

from : string

to : string

These properties indicate the state changes that trigger the transition.

The default values for these properties is "*" (that is, any state).

For example, the following transition has not set the to and from properties, so the animation is always applied when changing between the two states (i.e. when the mouse is pressed and released).

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

     MouseArea { id: mouseArea; anchors.fill: parent }

     states: State {
         name: "brighter"; when: mouseArea.pressed
         PropertyChanges { target: rect; color: "yellow" }
     }

     transitions: Transition {
         ColorAnimation { duration: 1000 }
     }
 }

If the transition was changed to this:

 transitions: Transition {
     to: "brighter"
     ColorAnimation { duration: 1000 }
 }

The animation would only be applied when changing from the default state to the "brighter" state (i.e. when the mouse is pressed, but not on release).

See also reversible.


reversible : bool

This property holds whether the transition should be automatically reversed when the conditions that triggered this transition are reversed.

The default value is false.

By default, transitions run in parallel and are applied to all state changes if the from and to states have not been set. In this situation, the transition is automatically applied when a state change is reversed, and it is not necessary to set this property to reverse the transition.

However, if a SequentialAnimation is used, or if the from or to properties have been set, this property will need to be set to reverse a transition when a state change is reverted. For example, the following transition applies a sequential animation when the mouse is pressed, and reverses the sequence of the animation when the mouse is released:

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

     MouseArea { id: mouseArea; anchors.fill: parent }

     states: State {
         name: "brighter"
         when: mouseArea.pressed
         PropertyChanges { target: rect; color: "yellow"; x: 50 }
     }

     transitions: Transition {
         SequentialAnimation {
             PropertyAnimation { property: "x"; duration: 1000 }
             ColorAnimation { duration: 1000 }
         }
     }
 }

If the transition did not set the to and reversible values, then on the mouse release, the transition would play the PropertyAnimation before the ColorAnimation instead of reversing the sequence.


Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. 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