Qtアニメーションフレームワーク

Qt 4.6の登場により、プロジェクトでのアニメーションの実装は最小限に簡素化されました。



コンポーネントプロパティのアニメーションが必要な場合、Qt 4.6はQPropertyAnimationクラスの使用を提案します。 次に、ウィジェットのサイズ変更アニメーションの例を示します。



#include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  1. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  2. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  3. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  4. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  5. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  6. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  7. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  8. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  9. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  10. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  11. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



  12. #include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .



#include <QWidget> #include <QPropertyAnimation> #include <QEasingCurve> class MyWidget : public QWidget { public : MyWidget(QObject* parent = 0); // MyWidget fields and methods public slots: void startAnimation(); private : QPropertyAnimation* _propertyAnimation; }; * This source code was highlighted with Source Code Highlighter .











  1. MyWidget :: MyWidget(QObject * parent):QWidget(parent){
  2. //ウィジェットの初期化
  3. _propertyAnimation = new QPropertyAnimation( this"geometry" );
  4. _propertyAnimation-> setDuration(1000);
  5. _propertyAnimation-> setEasingCurve(QEasingCurve :: OutCubic);
  6. }
  7. void MyWidget :: startAnimation(){
  8. QRectF firstPosition;
  9. QRectF endPosition;
  10. //最初の値と終了値の初期化
  11. _propertyAnimation-> setFirstValue(firstPosition);
  12. _propertyAnimation-> setEndValue(endPosition);
  13. _propertyAnimation-> start();
  14. }
*このソースコードは、 ソースコードハイライターで強調表示されました。




setDuration(int)メソッドを使用すると、アニメーションの継続時間が設定され、 setEasingCurve(const QEasingCurve&)メソッドを使用すると、値の曲線が時間とともに変化します。 この例では、 OutQuad曲線が選択されています。





実際には、6行とすべて。



非プロパティ値をアニメーション化するには、QVariantAnimationから継承し、 void updateCurrentValue(const QVariant&)メソッドをオーバーライドできます。 このメソッドでは、値が変更されたときに何が起こるかについてのロジックを記述する必要があります。



QVariantAnimationは、Int、Double、Float、QLine、QLineF、QPoint、QSize、QSizeF、QRect、QRectFの各タイプをサポートしています。 変更される値のタイプが上記のいずれにも属さない場合、 仮想QVariant補間(const QVariant&from、const QVariant&to、qreal progress)constの補間方法を再定義する必要があります



発生した例を次に示します。




All Articles