3.8 程序启动画面
许多应用程序都会在启动的时候显示一个程序启动画面(splash screen)。一些程序员使用程序启动画面对缓慢的启动过程进行掩饰,而另外一些人则是用于满足市场部门的要求。使用QSplashScreen类,可以非常容易地为Qt应用程序添加一个程序启动画面。
类QSplashScreen会在应用程序的主窗口出现之前显示一个图片。它也可以在这个图片上显示一些消息,用来通知用户有关应用程序初始化的过程。通常,程序启动画面的代码会放在main()函数中,位于QApplication::exec()调用之前。
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//程序启动画面
QSplashScreen* splash = new QSplashScreen;
splash->setPixmap(QPixmap(":/images/icon.png"));
splash->show();
Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(QObject::tr("Setting up the main window..."), topRight, Qt::white);
return a.exec();
}