实现效果
设计思路
利用qt的动画类,实现窗口的移动动画进行设计。
载入窗口,先创建窗口后显示,再设置动画启动点与结束点,即可实现窗口移动载入;关闭窗口即执行相反的操作即可。
代码实现
下面代码对OverviewWindow 窗口实现动画载入与关闭。
#include "overviewwindow.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QRect>
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;
});
});