RotationAnimation QML Type | Qt Quick (original) (raw)

Animates changes in rotation values. More...

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; a rotation from 0 to 240 will rotate 240 degrees clockwise, while a rotation from 240 to 0 will rotate 240 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 QtQuick

Item { width: 300; height: 300

[Rectangle](qml-qtquick-rectangle.html) {
    id: rect
    width: 150; height: 100; anchors.centerIn: parent
    color: "red"
    antialiasing: true

    states: State {
        name: "rotated"
        [PropertyChanges](qml-qtquick-propertychanges.html) { target: rect; rotation: 180 }
    }

    transitions: Transition {
        [RotationAnimation](qml-qtquick-rotationanimation.html) { duration: 1000; direction: RotationAnimation.Counterclockwise }
    }
}

[MouseArea](qml-qtquick-mousearea.html) { 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.

Also, note the Rectangle will be rotated around its default transformOrigin (which is Item.Center). To use a different transform origin, set the origin in the PropertyChanges object and apply the change at the start of the animation using PropertyAction. See the PropertyAction documentation for more details.

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 in Qt Quick documentation shows a variety of methods for creating animations.

See also Animation and Transitions in Qt Quick and Qt Quick Examples - Animation.

Property Documentation

This property holds the direction of the rotation.

Possible values are:

Constant Description
RotationAnimation.Numerical (default) Rotate by linearly interpolating between the two numbers. A rotation from 10 to 350 will rotate 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. A rotation from 10 to 350 will rotate 20 degrees counterclockwise.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.