QT5 设置开机动态启动画面

做个笔记,方便以后直接拿来用!                                                                          PS:欢迎批评、指正、交流

前几天突然想怎么能给自己的程序加个启动画面,就在网上查了一下,停留在搜索页面时,就看到满屏的 QSplashScreen ,就在编辑器上按下了F1,很轻易的就在类介绍里看到了这样的示例代码:

int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      QPixmap pixmap(":/splash.png");
      QSplashScreen splash(pixmap);
      splash.show();
      app.processEvents();
      ...
      QMainWindow window;
      window.show();
      splash.finish(&window);
      return app.exec();
  }
代码很简单,文档里也有相关的说明,但静态的画面好像已经不太能满足现在的需求了,所以继续查,就有了下面的代码,
新建一个应用程序的工程,修改main.cpp如下:
#include "mainwindow.h"
#include 
#include 
#include 
#include 
#include 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QPixmap pixmap(":/new/prefix1/233.gif");
    QMovie mv(":/new/prefix1/233.gif");
    QSplashScreen screen(pixmap);
    QLabel label(&screen);
    label.setMovie(&mv);
    mv.start();
    screen.show();
    int delayTime = 5;
    QElapsedTimer timer;
    timer.start();
    while(timer.elapsed() < (delayTime * 1000))
    {
        a.processEvents();
    }
    MainWindow w;
    w.show();
    screen.finish(&w);
    return a.exec();
}
代码同样不复杂,用QLabel来显示动态图,又加了个延时,显示自己的程序加载很复杂的样。各位要是有更好的方案,还请不吝赐教!


你可能感兴趣的:(漫漫QT路)