程序启动画面(QSplashScreen的使用)

程序

main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QSplashScreen>
#include <QLabel>
#include <windows.h>
#include <QMovie>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //静态程序启动画面
    /*QPixmap pixmap("Qt.png");
    QSplashScreen splash(pixmap);
    splash.show();
    a.processEvents();//使程序在显示启动动画时仍能响应鼠标等其他事件*/
    //动态程序启动画面
    QPixmap pix("splash2.gif");
    QSplashScreen splash(pix);
    //动态添加的步骤
    QLabel splashlabel(&splash);
    QMovie splashgif("splash2.gif");
    splashlabel.setMovie(&splashgif);
    splashgif.start();
    splash.show();
    splash.setCursor(Qt::BlankCursor);
    //使程序在显示启动动画时仍能响应鼠标等其他事件,使程序休眠几秒以便于动态态启动
    for(int i=0;i<15000;i+=splashgif.speed()){
        QCoreApplication::processEvents();
        Sleep(splashgif.speed()/3);
    }
    MainWindow w;
    w.show();
    splash.finish(&w);//在主窗体打开后结束启动动画

    return a.exec();
}

效果展示

静态

在这里插入图片描述
在这里插入图片描述

动态

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

发布了31 篇原创文章 · 获赞 3 · 访问量 289

猜你喜欢

转载自blog.csdn.net/weixin_44011306/article/details/105301122