一、动画框架

  Qt中的动画框架可以在帮助中查看The Animation Framework关键字,主要的类如下图所示,基类QAbstractAnimation中定义了动画开始、暂停、停止等方法,它也可以接收时间变化的通知,通过集成它可以创建自定义的动画类。QPropertyAnimation类用来执行Qt属性的动画,如果要对一个值使用动画可以创建继承自QObject的类,然后在类中将该值定义为一个属性。Qt支持的可以进行插值的QVariant类型有int、float、double、QLine、QPoint、QSize、QRect、QColor等,比如可以在QWidget的帮助文档中查看它支持动画的属性。如果要实现复杂的动画,可以通过动画组QParallelAnimationGroup和QSequentialAnimationGroup来实现,它们的功能是作为其它动画类的容器,一个动画组还可以包含另外的动画组。动画框架也被设计为状态机框架的一部分。

1、使用动画框架 

  下面的示例为按钮部件的geometry属性创建了动画,实现了从(0, 0)移动到(25, 250)点,并且其宽高由100*30变换为200*60:

#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, "geometry"); //给按钮的geometry属性创建动画
    animation.setDuration(10000); //动画持续时间为10秒
    animation.setStartValue(QRect(0, 0, 100, 30)); //动画开始时geometry属性的值
    animation.setEndValue(QRect(250, 250, 200, 60)); //动画结束时geometry属性的值
    animation.start(); //开始动画

    return app.exec();
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案