C
Transition QML Type
Defines animated transitions that occur on state changes. More...
Import Statement: | import QtQuick |
Since: | Qt Quick Ultralite 1.0 |
Properties
- animations : list<Animation>
- from : string
- to : string
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 moved
state. In the moved
state, the rectangle's position changes to (50, 50), which is animated by Transition using Easing.InOutQuad
. This gives a visual indication that rectangle's state has changed from default to moved
.
import QtQuick 2.15 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 use 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: "*"; to: "middleRight" NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; duration: 2000; } }, Transition { from: "*"; to: "bottomLeft"; NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad; duration: 200; } }, //If any other rectangle is clicked, the icon will return //to the start position at a slow speed. Transition { from: "*"; to: "*"; NumberAnimation { easing.type: Easing.OutExpo; properties: "x,y"; duration: 4000; } } ]
If multiple Transitions are specified, only a single (best-matching) Transition is applied for any particular state change. In the example above, if the Rectangle enters a state other than "middleRight"
or "bottomLeft"
, the third Transition is carried out, meaning the icon is moved to the starting point.
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 Animation and Transitions, Using States, and Important Concepts in Qt Quick Ultralite - States, Transitions and Animations.
Property Documentation
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 (that is, 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 changes to this:
transitions: Transition { to: "brighter" ColorAnimation { duration: 1000 } }
The animation is applied only when changing from the default state to the "brighter" state (that is, when the mouse is pressed, but not on release).
Multiple to
and from
values can be set by using a comma-separated string.
[default] animations : list<Animation> |
This property holds a list of the animations to be run for this transition.
Item { 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:
Item { transitions: Transition { SequentialAnimation { PropertyAnimation { duration: 3000 } ColorAnimation { duration: 3000 } } } }
Available under certain Qt licenses.
Find out more.