C

RotationAnimation QML Type

Animates changes in rotation values. More...

Import Statement: import QtQuick .
Since: Qt Quick Ultralite 1.0
Inherits:

PropertyAnimation

Properties

Detailed Description

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. For example, a rotation from 0 to 240 rotates 240 degrees clockwise, while a rotation from 240 to 0 rotates 240 degrees counterclockwise. The direction property can be set to specify the direction in which the rotation should occur.

In the following example, RotationAnimation is used to animate the rotation between states via the shortest path:

import QtQuick 2.15

Rectangle {
    id: root
    color: "white"

    states: State {
        name: "rotated"
        PropertyChanges { target: rotation; angle: 180 }
    }

    transitions: Transition {
        RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }
    }

    Text {
        id: text
        anchors.centerIn: parent
        text: "rotated"
        transform: Rotation {
            id: rotation
            angle: 0
            origin.x: text.width / 2
            origin.y: text.height / 2
        }
    }

    MouseArea { anchors.fill: parent; onClicked: root.state = "rotated" }
}

Note: The RotationAnimation does not automatically limit itself to the "rotation" and "angle" properties. Use properties or property to select the properties for animation. This is a difference to Qt Quick.

Like any other animation type, a RotationAnimation can be applied in a number of ways, including transitions, behaviors, and property value sources. The Animation and Transitions documentation describes a variety of methods for creating animations.

See also Animation and Transitions.

Property Documentation

direction : enumeration

This property holds the direction of the rotation.

Possible values are:

  • RotationAnimation.Numerical (default) - Rotate by linearly interpolating between the two numbers. For example, a rotation from 10 to 350 rotates 340 degrees clockwise.
  • RotationAnimation.Clockwise - Rotate clockwise between the two values
  • RotationAnimation.Counterclockwise - Rotate counterclockwise between the two values
  • RotationAnimation.Shortest - Rotate in the direction that produces the shortest animation path. For example, a rotation from 10 to 350 rotates 20 degrees counterclockwise.

from : real

This property holds the starting value for the animation.

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 the RotationAnimation is defined within a Transition or Behavior, this value defaults to the value defined in the starting state of the Transition, or the current value of the property at the moment the Behavior is triggered.

See also Animation and Transitions.


to : real

This property holds the end value for the animation.

If the RotationAnimation is defined within a Transition or Behavior, this value defaults to the value defined in the end state of the Transition, or the value of the property change that triggered the Behavior.

See also Animation and Transitions.


Available under certain Qt licenses.
Find out more.