Qt Animation Framework ,该框架提供了一些预定义的动画效果,如淡入淡出、旋转、缩放等,并且可以自定义动画效果。
以下是一个简单的演示如何使用 Qt Animation Framework 来实现一个简单的动画效果:
#include <QApplication>
#include <QLabel>
#include <QPropertyAnimation>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label("Hello, Qt!");
label.show();
QPropertyAnimation *animation = new QPropertyAnimation(&label, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(0, 0, 100, 30));
animation->setEndValue(QRect(250, 250, 100, 30));
animation->start();
return a.exec();
}
上述代码创建了一个 QLabel 对象,并且使用 QPropertyAnimation 类来定义一个动画效果,将 QLabel 对象从初始位置移动到终止位置。setDuration() 方法设置动画的持续时间,setStartValue() 和 setEndValue() 方法设置起始和终止位置。
最后,调用 start() 方法启动动画效果。
QPropertyAnimation 类只能用于对QObject的属性进行动画处理,如果需要对QWidget进行动画处理,需要使用QAbstractAnimation类。