Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QSplashScreen Class Reference

The QSplashScreen widget provides a splash screen that can be shown during application startup. More...

#include <qsplashscreen.h>

Inherits QWidget.

List of all member functions.

Public Members

Public Slots

Signals

Protected Members


Detailed Description

The QSplashScreen widget provides a splash screen that can be shown during application startup.

A splash screen is a widget that is usually displayed when an application is being started. Splash screens are often used for applications that have long start up times (e.g. database or networking applications that take time to establish connections) to provide the user with feedback that the application is loading.

The splash screen will be on top of all the windows and centered on the screen. Some X11 window managers do not support the "stays on top" flag, in such cases it may be necessary to set up a timer that periodically calls raise() on the splash screen to get the "stays on top" effect.

The most common usage is to show a splash screen before the main widget is displayed on the screen. This is illustrated in the following code snippet.

   int main( int argc, char **argv )
   {
       QApplication app( argc, argv );
       QPixmap pixmap( "splash.png" );
       QSplashScreen *splash = new QSplashScreen( pixmap );
       splash->show();
       QMainWindow *mainWin = new QMainWindow;
       ...
       app.setMainWidget( mainWin );
       mainWin->show();
       splash->finish( mainWin );
       delete splash;
       return app.exec();
   }
   

It is sometimes useful to update the splash screen with messages, for example, announcing connections established or modules loaded as the application starts up. QSplashScreen supports this with the message() function. If you wish to do your own drawing you can get a pointer to the pixmap used in the splash screen with pixmap(). Alternatively, you can subclass QSplashScreen and reimplement drawContents().

The user can hide the splash screen by clicking on it with the mouse. Since the splash screen is typically displayed before the event loop has started running, it is necessary to periodically call QApplication::processEvents() to receive the mouse clicks.

   QSplashScreen *splash = new QSplashScreen( "splash.png" );
   splash->show();
   ... // Loading some items
   splash->message( "Loaded modules" );
   qApp->processEvents();
   ... // Establishing connections
   splash->message( "Established connections" );
   qApp->processEvents();
   

See also Miscellaneous Classes.


Member Function Documentation

QSplashScreen::QSplashScreen ( const QPixmap & pixmap = QPixmap ( ), WFlags f = 0 )

Construct a splash screen that will display pixmap.

There should be no need to set the widget flags, f, other than perhaps WDestructiveClose.

QSplashScreen::~QSplashScreen () [virtual]

Destructor.

void QSplashScreen::clear () [slot]

Removes the message being displayed on the splash screen

See also message().

void QSplashScreen::drawContents ( QPainter * painter ) [virtual protected]

Draw the contents of the splash screen using painter painter. The default implementation draws the message passed by message(). Reimplement this function if you want to do your own drawing on the splash screen.

void QSplashScreen::finish ( QWidget * mainWin )

Makes the splash screen wait until the widget mainWin is displayed before calling close() on itself.

void QSplashScreen::message ( const QString & message, int alignment = AlignLeft, const QColor & color = black ) [slot]

Draws the message text onto the splash screen with color color and aligns the text according to the flags in alignment.

See also Qt::AlignmentFlags and clear().

void QSplashScreen::messageChanged ( const QString & message ) [signal]

This signal is emitted when the message on the splash screen changes. message is the new message and is a null-string when the message has been removed.

See also message() and clear().

QPixmap * QSplashScreen::pixmap () const

Returns the pixmap that is used in the splash screen, minus any text possibly set with message().

void QSplashScreen::repaint ()

This is an override of QWidget::repaint(). It differs from the standard repaint function in that it additionally calls QApplication::flush() to ensure the updates are displayed when there is no event loop present.

void QSplashScreen::setPixmap ( const QPixmap & pixmap )

Set the pixmap that will be used as the image of the splash screen to pixmap.

This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.


Copyright © 2003 TrolltechTrademarks
Qt version 3.2.0b2