The RotationAnimation element animates changes in rotation values. More...
Inherits PropertyAnimation
RotationAnimation is a specialized PropertyAnimation that gives control over the direction of rotation during an animation.
By default, it rotates in the direction of the numerical change; a rotation from 0 to 240 will rotate 220 degrees clockwise, while a rotation from 240 to 0 will rotate 220 degrees counterclockwise. The direction property can be set to specify the direction in which the rotation should occur.
In the following example we use RotationAnimation to animate the rotation between states via the shortest path:
import Qt 4.7 Item { width: 300; height: 300 Rectangle { id: rect width: 150; height: 100; anchors.centerIn: parent color: "red" smooth: true states: State { name: "rotated"; PropertyChanges { target: rect; rotation: 180 } } transitions: Transition { RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise } } } MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" } }
Notice the RotationAnimation did not need to set a target value. As a convenience, when used in a transition, RotationAnimation will rotate all properties named "rotation" or "angle". You can override this by providing your own properties via properties or property.
Like any other animation element, a RotationAnimation can be applied in a number of ways, including transitions, behaviors and property value sources. The QML Animation documentation shows a variety of methods for creating animations.
See also QML Animation and Animation basics example.
direction : enumeration |
This property holds the direction of the rotation.
Possible values are:
from : real |
This property holds the starting number value.
For example, the following animation is not applied until the angle value has reached 100:
Item { states: [ ... ] transition: Transition { RotationAnimation { properties: "angle"; from: 100; duration: 2000 } } }
If this value is not set, it defaults to the value defined in the start state of the Transition.
to : real |
This property holds the ending value.
If this value is not set, it defaults to the value defined in the end state of the Transition or Behavior.