Flylib.com

Books Software

 
 
 

Splash Screens

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.

Chapter 4. Implementing Application Functionality

  • The Central Widget

  • Subclassing QTable

  • Loading and Saving

  • Implementing the Edit Menu

  • Implementing the Other Menus

  • Subclassing QTableItem

In the previous two chapters, we explained how to create the Spreadsheet application's user interface. In this chapter, we will complete the program by coding its underlying functionality. Among other things, we will see how to load and save files, how to store data in memory, how to implement clipboard operations, and how to add support for spreadsheet formulas to QTable .

The Central Widget

The central area of a QMainWindow can be occupied by any kind of widget. Here's an overview of the possibilities:

  1. Use a standard Qt widget .

    A standard widget like QTable or QTextEdit can be used as a central widget. In this case, the application's functionality, such as loading and saving files, must be implemented elsewhere (for example, in a QMainWindow subclass).

  2. Use a custom widget .

    Specialized applications often need to show data in a custom widget. For example, an icon editor program would have an IconEditor widget as its central widget. Chapter 5 explains how to write custom widgets in Qt.

  3. Use a plain QWidget with a layout manager .

    Sometimes the application's central area is occupied by many widgets. This can be done by using a QWidget as the parent of all the other widgets, and using layout managers to size and position the child widgets.

  4. Use a splitter .

    Another way of using multiple widgets together is to use a QSplitter . The QSplitter arranges its child widgets side by side like a QHBox , or in a column like a QVBox , with splitter handles to give some sizing control to the user . Splitters can contain all kinds of widgets, including other splitters.

  5. Use an MDI workspace .

    If the application uses MDI, the central area is occupied by a QWorkspace widget, and each of the MDI windows is a child of that widget.

Layouts, splitters, and MDI workspaces can be used in combination with standard Qt widgets or with custom widgets. Chapter 6 covers these classes in depth.

For the Spreadsheet application, a QTable subclass is used as the central widget. The QTable class already provides most of the spreadsheet capability we need, but it doesn't understand spreadsheet formulas like "=A1+A2+A3", and it doesn't support clipboard operations. We will implement this missing functionality in the Spreadsheet class, which inherits from QTable .