Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML Animation with both "velocity" and infinite "loops"

Tags:

qt

qt-quick

qml

I'm trying to put together an animation in which I get to specify the velocity (rather than the duration) and which loops forever. I came up with two non-working examples:

FirstTry.qml

import Qt 4.7

Rectangle {
  width: 100; height: 100
  Text {
    text: "hello"
    NumberAnimation on x {
      to: 50;
      loops: Animation.Infinite;
      duration: 50 * Math.abs(to - from)
    }
  }
}

I get the following runtime warning while hello goes nuts on the screen (fair enough).

QDeclarativeExpression: Expression "(function() { return 50 * Math.abs(to - from) })" depends on non-NOTIFYable properties: 
    QDeclarativeNumberAnimation::to
    QDeclarativeNumberAnimation::from

SecondTry.qml

import Qt 4.7

Rectangle {
  width: 100; height: 100
  Text {
    text: "hello"
    SmoothedAnimation on x {
      to: 50;
      loops: Animation.Infinite;
      velocity: 50
    }
  }
}

This is more of a mistery -- SmoothedAnimation simply refuses to loop! The Animation runs once and then that's it.

So I have the following questions:

Is there a legal way to specify the velocity in the first example? I understand SmoothedAnimation is derived from NumberAnimation, so maybe it's possible in QML, not just in C++.

Is there a way to make SmoothedAnimation loop? Is the second example not working a bug or am I missing something?

Is there any other way to achieve these two behaviours at the same time?

like image 819
xcvii Avatar asked Oct 11 '22 04:10

xcvii


1 Answers

just add "from" parameter explicitly:

import Qt 4.7

Rectangle {
  width: 100; height: 100
  Text {
    text: "hello"
    NumberAnimation on x {
      from: 0;
      to: 50;
      loops: Animation.Infinite;
      duration: 50 * Math.abs(to - from)
    }
  }
}
like image 134
tuxedo Avatar answered Oct 18 '22 03:10

tuxedo