Splash Screens

Many applications present a splash screen at startup. Some developers use a splash screen to disguise a slow startup, while others do it to satisfy their marketing departments. Adding a splash screen to Qt applications is very easy using the QSplashScreen class.

The QSplashScreen class shows an image before the application proper has started. It can also draw a message on the image, to inform the user about the progress of the application's initialization process. Typically, the splash screen code is located in main(), before the call to QApplication::exec().

Below is an example main() function that uses QSplashScreen to present a splash screen in an application that loads modules and establishes network connections at startup.

int main(int argc, char *argv[])
{
 QApplication app(argc, argv);
 QSplashScreen *splash =
 new QSplashScreen(QPixmap::fromMimeSource("splash.png"));
 splash->show();

 splash->message(QObject::tr("Setting up the main window..."),
 Qt::AlignRight | Qt::AlignTop, Qt::white);
 MainWindow mainWin;
 app.setMainWidget(&mainWin);

 splash->message(QObject::tr("Loading modules..."),
 Qt::AlignRight | Qt::AlignTop, Qt::white);
 loadModules();

 splash->message(QObject::tr("Establishing connections..."),
 Qt::AlignRight | Qt::AlignTop, Qt::white);
 establishConnections();

 mainWin.show();
 splash->finish(&mainWin);
 delete splash;

 return app.exec();
}

Figure 3.18. A QSplashScreen widget

graphics/03fig18.gif

We have now completed the Spreadsheet application's user interface. In the next chapter, we will complete the application by implementing the core spreadsheet functionality.





C++ GUI Programming with Qt 3
C++ GUI Programming with Qt 3
ISBN: 0131240722
EAN: 2147483647
Year: 2006
Pages: 140
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net