[Interest] [Qt3d] Does the duration of NumberAnimation update when you change its value?

Sean Harmer sean.harmer at kdab.com
Mon Apr 25 18:45:15 CEST 2016


On Monday 25 April 2016 16:23:31 Ramy Atalla via Interest wrote:
> Hi,I am trying to do a rotation animation and control the rotation speed by
> changing the value of the duration, But it doesn't work . My question is it
> feasible or there another way ?
> QQ2.NumberAnimation {    id:wheelanimation     property int carspeed:0   
> targets: [wheel1Transform , rim1Transform,wheel2Transform ,
> rim2Transform,wheel3Transform ,             rim3Transform,wheel4Transform ,
> rim4Transform]    property: "userAngle"    duration: carspeed    from: 0   
> to: 360    loops: QQ2.Animation.Infinite    running: true }
> QQ2.NumberAnimation {    duration: 100    loops: QQ2.Animation.Infinite   
> target: wheelanimation    property: "carspeed"    from: 0.0    to: 3000   
> running: true }

I don't think this works unless you stop/restart the animation which is not 
ideal. A work around is to have a simple NumberAnimation changing a "progress" 
value, then in your actual property that you wish to animate, multiply this 
progress property by your rotationSpeed property. It requires some extra 
gymnastics to cope with non-integer numbers of rotations per cycle of the 
progress property.

Something like this should do it (not tested):

Entity {
    id: root
    property real progress: 0.0
    property real rotationSpeed: 10.0
    property real angle: previousAngle + ( progress * rotationSpeed )
    property real previousAngle: 0.0

    function updatePreviousRotation() {
        root.previousAngle = root.angle;

    SequentialAnimation {
        running: true
        loops: Animation.Infinite
        NumberAnimation {
            from: 0; to: 1
            duration: 1000

        ScriptAction { script: updatePreviousRotation() }

This is a limitation of what can be expressed with the Qt Quick 2 animation 
framework at present. When we look at adding an animation aspect to Qt 3D for 
Qt 5.8 or 5.9, this is one of the things I want to address along with morph 
target, key frame and skeletal animations. More likely for 5.9 given we're 
already well into the development cycle for 5.8 and we're still putting all 
efforts into 5.7.

Hope this helps,

Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. UK +44 (0)1625 809908, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions

More information about the Interest mailing list