
Qt Animation Framework
With the advent of Qt 4.6, the implementation of animation in the project has been simplified to a minimum.
In the event that animation of component properties is needed, Qt 4.6 suggests using the QPropertyAnimation class . Here is an example widget resize animation:
Using the setDuration (int) method, the duration of the animation is set, and using the setEasingCurve (const QEasingCurve &) method, the curve of the value changes over time. In this example, the OutQuad curve is selected.

Actually, 6 lines and all.
To animate a non-property value, you can inherit from QVariantAnimation and override the void updateCurrentValue (const QVariant &) method . In this method, it is necessary to describe the logic of what should happen when the value changes.
QVariantAnimation supports the following types: Int, Double, Float, QLine, QLineF, QPoint, QSize, QSizeF, QRect, QRectF. If the type of the value being changed does not belong to any of the above, you need to redefine the interpolation method virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress) const
Here is an example of what happened:
In the event that animation of component properties is needed, Qt 4.6 suggests using the QPropertyAnimation class . Here is an example widget resize animation:
- #include
- #include
- #include
-
- 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) {
- // Widget initialization
- _propertyAnimation = new QPropertyAnimation(this,"geometry");
- _propertyAnimation->setDuration(1000);
- _propertyAnimation->setEasingCurve(QEasingCurve::OutCubic);
- }
-
- void MyWidget::startAnimation() {
- QRectF firstPosition;
- QRectF endPosition;
- // Initializing first and end values
- _propertyAnimation->setFirstValue(firstPosition);
- _propertyAnimation->setEndValue(endPosition);
- _propertyAnimation->start();
- }
* This source code was highlighted with Source Code Highlighter.
Using the setDuration (int) method, the duration of the animation is set, and using the setEasingCurve (const QEasingCurve &) method, the curve of the value changes over time. In this example, the OutQuad curve is selected.

Actually, 6 lines and all.
To animate a non-property value, you can inherit from QVariantAnimation and override the void updateCurrentValue (const QVariant &) method . In this method, it is necessary to describe the logic of what should happen when the value changes.
QVariantAnimation supports the following types: Int, Double, Float, QLine, QLineF, QPoint, QSize, QSizeF, QRect, QRectF. If the type of the value being changed does not belong to any of the above, you need to redefine the interpolation method virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress) const
Here is an example of what happened: