欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Qt简单属性动画、组合动画.md

程序员文章站 2022-03-02 19:44:01
...

Qt属性动画,QPropertyAnimation初始化时绑定指定的对象和对象的属性,设置属性的起始值和终止值还有执行时间,需要的话加入到QSequentialAnimationGroup中,start即可。

初始化动画,连接触发动画的信号就好:

#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    /////////////////////////初始化动画//////////////////////
    QSequentialAnimationGroup * animate_ = new QSequentialAnimationGroup(this);   
    QPropertyAnimation * animate = new QPropertyAnimation(ui->pushButton,"pos");
    animate->setEndValue(QPoint(100,200));
    animate->setDuration(1000);
    animate_->addAnimation(animate);
    animate_->addPause(500);
    animate->setEasingCurve(QEasingCurve::OutCirc);
    animate = new QPropertyAnimation(ui->pushButton,"pos");
    animate->setEndValue(QPoint(50,50));
    animate->setDuration(2000);
    animate->setEasingCurve(QEasingCurve::InCirc);
    animate_->addAnimation(animate);
    connect(ui->pushButton,SIGNAL(clicked()),animate_,SLOT(start()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

代码:https://github.com/yangyang0312/QtTestCode/tree/master/testAnimate