コンポーネントプロパティのアニメーションが必要な場合、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 .
#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 .
#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 .
#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 .
#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 .
#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 .
#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 .
#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 .
*このソースコードは、 ソースコードハイライターで強調表示されました。
- MyWidget :: MyWidget(QObject * parent):QWidget(parent){
- //ウィジェットの初期化
- _propertyAnimation = new QPropertyAnimation( this 、 "geometry" );
- _propertyAnimation-> setDuration(1000);
- _propertyAnimation-> setEasingCurve(QEasingCurve :: OutCubic);
- }
- void MyWidget :: startAnimation(){
- QRectF firstPosition;
- QRectF endPosition;
- //最初の値と終了値の初期化
- _propertyAnimation-> setFirstValue(firstPosition);
- _propertyAnimation-> setEndValue(endPosition);
- _propertyAnimation-> start();
- }
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の補間方法を再定義する必要があります
発生した例を次に示します。