Allows a property to track a value in a spring-like motion. More...

Import Statement: import QtQuick 2.11



Detailed Description

SpringAnimation mimics the oscillatory behavior of a spring, with the appropriate spring constant to control the acceleration and the damping to control how quickly the effect dies away.

You can also limit the maximum velocity of the animation.

The following Rectangle moves to the position of the mouse using a SpringAnimation when the mouse is clicked. The use of the Behavior on the x and y values indicates that whenever these values are changed, a SpringAnimation should be applied.

import QtQuick 2.0

Item {
    width: 300; height: 300

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

        Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } }
        Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            rect.x = mouse.x - rect.width/2
            rect.y = mouse.y - rect.height/2

Like any other animation type, a SpringAnimation 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 SmoothedAnimation, Animation and Transitions in Qt Quick, Qt Quick Examples - Animation, and Qt Quick Demo - Clocks.

Property Documentation

damping : real

This property holds the spring damping value.

This value describes how quickly the spring-like motion comes to rest. The default value is 0.

The useful value range is 0 - 1.0. The lower the value, the faster it comes to rest.

epsilon : real

This property holds the spring epsilon.

The epsilon is the rate and amount of change in the value which is close enough to 0 to be considered equal to zero. This will depend on the usage of the value. For pixel positions, 0.25 would suffice. For scale, 0.005 will suffice.

The default is 0.01. Tuning this value can provide small performance improvements.

mass : real

This property holds the "mass" of the property being moved.

The value is 1.0 by default.

A greater mass causes slower movement and a greater spring-like motion when an item comes to rest.

modulus : real

This property holds the modulus value. The default value is 0.

Setting a modulus forces the target value to "wrap around" at the modulus. For example, setting the modulus to 360 will cause a value of 370 to wrap around to 10.

spring : real

This property describes how strongly the target is pulled towards the source. The default value is 0 (that is, the spring-like motion is disabled).

The useful value range is 0 - 5.0.

When this property is set and the velocity value is greater than 0, the velocity limits the maximum speed.

velocity : real

This property holds the maximum velocity allowed when tracking the source.

The default value is 0 (no maximum velocity).

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
create apps
create games
cross platform
native performance
3rd party services
game network
level editor
easiest to learn
biggest time saving
best support