qt动画载入、关闭窗口

实现效果

qt动画载入、关闭窗口_第1张图片

设计思路

利用qt的动画类,实现窗口的移动动画进行设计。
载入窗口,先创建窗口后显示,再设置动画启动点与结束点,即可实现窗口移动载入;关闭窗口即执行相反的操作即可。

代码实现

下面代码对OverviewWindow 窗口实现动画载入与关闭。

#include "overviewwindow.h"
#include 
#include 
#include 
	OverviewWindow *overview = new OverviewWindow(this);
    overview->show();
    //载入窗口的动画
    QPropertyAnimation *pAnimation = new QPropertyAnimation(overview,"geometry",this);
    pAnimation->setDuration(1000);
    pAnimation->setEasingCurve(QEasingCurve::OutBounce);
    pAnimation->setStartValue(QRect(this->x(),this->y()
                              ,overview->width(),overview->height()));
    QDesktopWidget *desktop = QApplication::desktop();
    pAnimation->setEndValue(QRect((desktop->width()-this->width())/2
                            ,(desktop->height()-this->height())/2
                            ,overview->width()
                            ,overview->height()));
    pAnimation->start();
    connect(overview,&OverviewWindow::closeThis,this,[=]()
    {
        //关闭窗口的动画
        pAnimation->setEasingCurve(QEasingCurve::InQuart);
        QDesktopWidget *desktop = QApplication::desktop();
        pAnimation->setStartValue(QRect((desktop->width()-this->width())/2
                                ,(desktop->height()-this->height())/2
                                ,overview->width()
                                ,overview->height()));
        pAnimation->setEndValue(QRect(this->x(),this->y()
                                      ,overview->width(),overview->height()));
        pAnimation->start();
        connect(pAnimation,&QPropertyAnimation::finished,[=]{
            delete overview;
            delete pAnimation;
        });
    });

你可能感兴趣的:(C++\QT,动画,qt,弹窗)