应用程序(exe)在启动时,由于初始化时间过长时,需要使用启动动画。
auto splash = new QSplashScreen;
QPixmap pixmap(":/main/splash.png"); // 启动图片
splash->setPixmap(pixmap);
splash->setAttribute(Qt::WA_DeleteOnClose); // 关闭时销毁窗口
splash->show();
splash->showMessage("Loading...", Qt::AlignRight | Qt::AlignBottom, Qt::black);
app.processEvents(); //接收鼠标消息
如果加载过程中,显示的消息不同时,需要使用showMessage更新。
splash->raise(); // 前置显示
splash->showMessage("updating splash...",Qt::AlignRight | Qt::AlignBottom, Qt::black);
app->processEvents();
在app.exec()之前,关闭启动画面,splash->finish(&appWin);
启动画面一般在main函数内执行。