Search code examples
qtqml

How to apply a smooth rotation animation on my needle rotation property?


I have below QML. I need to apply a smooth animation on rotation. 'mycontroller' from c++ code will gives incremented gauge values in frequent intervals (say in 500 msecs). so I need a smooth transition on rotation.

Rectangle {
   id : gauge
   property real value : mycontroller.value

   Image {
        id : needle
        x:50
        y:190
        z: -2
        rotation: gauge.value
        transformOrigin: Item.Right
        source : "qrc:/images/needle.png";
   }
}

Solution

  • You should use a behavior based approach:

    Behavior on rotation { NumberAnimation { duration: 200 } }