开发者

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

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?


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)
    }
  }
}


This is what I did as a temporary solution, I'm not sure if it's adequate, but it seem to be doing just what I needed.

SmoothedAnimation on x {
  to: 50;
  //loops: Animation.Infinite;
  velocity: 50
  onComplete: { restart (); }
}

I'm still interested in the answers to the questions, though.


Even if SmoothedAnimation doesn't accept loops parameter, you can place it inside SequentialAnimation and apply loops to this external cover. As an effect your smoothed animation will be played continuosly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜