5.4 设置应用程序启动画面
QSplashScreen类提供了一个加载应用程序启动画面的功能,可在应用程序启动期间显示一些提示信息,输出的信息主体是一张图片,可以在图片上描述应用程序的版权,作者,功能等信息。启动画面功能通常用于应用程序需要长时间启动加载情况,可以为用户应用程序加载启动的反馈信息。(例如:数据库或网络应用程序需要时间来建立连接)。
5.4.1 创建应用程序启动画面完整程序参考(配套程序编号CH5-3)。
#include "mainwindow.h"
#include
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmapSplash(":/image/splash.png"); //加载像素图片
QSplashScreen Splash(pixmapSplash); //构造启动画面
Splash.show(); //显示启动画面
Splash.showMessage(QObject::tr("应用程序加载中..."), Qt::AlignLeft|Qt::AlignBottom );
a.processEvents(); //启动应用程序的事件处理
/*编写主窗口启动前需要执行的代码*/
MainWindow w; //主窗体
w.thread()->sleep(3); //这里表示延时3秒,否则闪屏结束太快看不到效果,正常情况下不需要延时。
w.show();