5

(持続時間ではなく) 速度を指定し、永久にループするアニメーションをまとめようとしています。うまくいかない例を 2 つ思いつきました。

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

画面が狂っている間に、次の実行時警告helloが表示されます(十分です)。

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

これはもっとミステリーです -SmoothedAnimation単純にループを拒否します! アニメーションは 1 回実行され、それで終わりです。

だから私は次の質問があります:

最初の例で速度を指定する合法的な方法はありますか? SmoothedAnimationが から派生していることを理解NumberAnimationしているので、C++ だけでなく QML でも可能かもしれません。

SmoothedAnimationループを作る方法はありますか?2 番目の例はバグで動作していませんか、それとも何か不足していますか?

これら 2 つの動作を同時に達成する他の方法はありますか?

4

3 に答える 3

4

「from」パラメータを明示的に追加するだけです:

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)
    }
  }
}
于 2014-04-19T16:34:07.813 に答える