当前位置:网站首页>QT animation loading and closing window

QT animation loading and closing window

2022-06-25 15:07:00 Knowledge first

Realization effect

 Insert picture description here

Design thinking

utilize qt Animation class of , Realize the moving animation of the window .
Load window , First create a window and then display , Then set the animation start point and end point , You can move and load the window ; Close the window and perform the opposite operation .

Code implementation

The following code pairs OverviewWindow Window to achieve animation loading and closing .

#include "overviewwindow.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QRect>
	OverviewWindow *overview = new OverviewWindow(this);
    overview->show();
    // Load the animation of the window 
    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,[=]()
    {
    
        // Close window animation 
        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;
        });
    });
原网站

版权声明
本文为[Knowledge first]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200512307542.html