
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQSplashScreen widget provides a splash screen that can be shown during application startup.More...
| Header: | #include <QSplashScreen> |
| Inherits: | QWidget |
| QSplashScreen(const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0) | |
| QSplashScreen(QWidget * parent, const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = 0) | |
| virtual | ~QSplashScreen() |
| void | finish(QWidget * mainWin) |
| const QPixmap | pixmap() const |
| void | repaint() |
| void | setPixmap(const QPixmap & pixmap) |
| void | clearMessage() |
| void | showMessage(const QString & message, int alignment = Qt::AlignLeft, const QColor & color = Qt::black) |
| void | messageChanged(const QString & message) |
| virtual void | drawContents(QPainter * painter) |
| virtual bool | event(QEvent * e) |
| virtual void | mousePressEvent(QMouseEvent *) |
TheQSplashScreen 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 appears in the center of the screen. It may be useful to add theQt::WindowStaysOnTopHint to the splash widget's window flags if you want to keep it above all the other windows on the desktop.
Some X11 window managers do not support the "stays on top" flag. A solution is to set up a timer that periodically callsraise() on the splash screen to simulate 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 in which a splash screen is displayed and some initialization tasks are performed before the application's main window is shown:
int main(int argc,char*argv[]){QApplication app(argc, argv);QPixmap pixmap(":/splash.png");QSplashScreen splash(pixmap); splash.show(); app.processEvents(); ...QMainWindow window; window.show(); splash.finish(&window);return app.exec();}
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 callQApplication::processEvents() to receive the mouse clicks.
It is sometimes useful to update the splash screen with messages, for example, announcing connections established or modules loaded as the application starts up:
QPixmappixmap(":/splash.png");QSplashScreen*splash=newQSplashScreen(pixmap);splash->show();...// Loading some itemssplash->showMessage("Loaded modules");qApp->processEvents();...// Establishing connectionssplash->showMessage("Established connections");qApp->processEvents();
QSplashScreen supports this with theshowMessage() function. If you wish to do your own drawing you can get a pointer to the pixmap used in the splash screen withpixmap(). Alternatively, you can subclassQSplashScreen and reimplementdrawContents().
Construct a splash screen that will display thepixmap.
There should be no need to set the widget flags,f, except perhapsQt::WindowStaysOnTopHint.
This is an overloaded function.
This function allows you to specify a parent for your splashscreen. The typical use for this constructor is if you have a multiple screens and prefer to have the splash screen on a different screen than your primary one. In that case pass the proper desktop() as theparent.
[virtual]QSplashScreen::~QSplashScreen()Destructor.
[slot]void QSplashScreen::clearMessage()Removes the message being displayed on the splash screen
See alsoshowMessage().
[virtual protected]void QSplashScreen::drawContents(QPainter * painter)Draw the contents of the splash screen using painterpainter. The default implementation draws the message passed byshowMessage(). Reimplement this function if you want to do your own drawing on the splash screen.
[virtual protected]bool QSplashScreen::event(QEvent * e)Reimplemented fromQObject::event().
Makes the splash screen wait until the widgetmainWin is displayed before callingclose() on itself.
[signal]void QSplashScreen::messageChanged(constQString & message)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 alsoshowMessage() andclearMessage().
[virtual protected]void QSplashScreen::mousePressEvent(QMouseEvent *)Reimplemented fromQWidget::mousePressEvent().
Returns the pixmap that is used in the splash screen. The image does not have any of the text drawn byshowMessage() calls.
See alsosetPixmap().
This overridesQWidget::repaint(). It differs from the standard repaint function in that it also callsQApplication::flush() to ensure the updates are displayed, even when there is no event loop present.
Sets the pixmap that will be used as the splash screen's image topixmap.
See alsopixmap().
[slot]void QSplashScreen::showMessage(constQString & message,int alignment = Qt::AlignLeft, constQColor & color = Qt::black)Draws themessage text onto the splash screen with colorcolor and aligns the text according to the flags inalignment.
To make sure the splash screen is repainted immediately, you can callQCoreApplication'sprocessEvents() after the call to showMessage(). You usually want this to make sure that the message is kept up to date with what your application is doing (e.g., loading files).
See alsoQt::Alignment andclearMessage().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.