#include
QPropertyAnimation 类继承自 QVariantAnimation,并且可以与 QObject 的派生类结合使用,以实现对该对象的属性进行动画效果的控制。
下面是一个简单的示例代码,演示如何使用 QPropertyAnimation 来实现一个简单的平移动画:
#include <QApplication>
#include <QPushButton>
#include <QPropertyAnimation>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton button("Animated Button");
button.show();
// 创建一个按钮平移动画
QPropertyAnimation animation(&button, "pos");
// 设置动画持续时间和目标位置
animation.setDuration(2000);
animation.setEndValue(QPoint(200, 200));
// 启动动画
animation.start();
return app.exec();
}
上述代码创建了一个 QPushButton 对象,并创建了一个 QPropertyAnimation 对象,将其应用于按钮的 “pos” 属性(即位置)。然后设置了动画的持续时间和目标位置,并启动了动画。通过这段代码,按钮会从初始位置平滑地移动到目标位置。
总之,
内容由零声教学AI助手提供,问题来源于学员提问