QSplashScreen露
The
QSplashScreenwidget provides a splash screen that can be shown during application startup. More鈥

Synopsis露
Functions露
Virtual functions露
def
drawContents(painter)
Slots露
def
clearMessage()def
showMessage(message[, alignment=Qt.AlignLeft[, color=Qt.black]])
Signals露
def
messageChanged(message)
Detailed Description露
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 the
WindowStaysOnTopHintto the splash widget鈥檚 window flags if you want to keep it above all the other windows on the desktop.Some X11 window managers do not support the 鈥渟tays on top鈥 flag. A solution is to set up a timer that periodically calls
raise()on the splash screen to simulate the 鈥渟tays 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鈥檚 main window is shown:
def main(): app = QApplication(sys.argv) pixmap = QPixmap(":/splash.png") splash = QSplashScreen(pixmap) splash.show() app.processEvents() ... window = QMainWindow() 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 call
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:
pixmap = QPixmap(":/splash.png") splash = QSplashScreen(pixmap) splash.show() ... # Loading some items splash.showMessage("Loaded modules") qApp.processEvents() ... # Establishing connections splash.showMessage("Established connections") qApp.processEvents()
QSplashScreensupports 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 subclassQSplashScreenand reimplementdrawContents().In case of having multiple screens, it is also possible to show the splash screen on a different screen than the primary one. For example:
QScreen *screen = QGuiApplication::screens().at(1); QPixmap pixmap(":/splash.png"); QSplashScreen splash(screen, pixmap); splash.show();
- class PySide2.QtWidgets.QSplashScreen(screen[, pixmap=QPixmap()[, f=Qt.WindowFlags()]])露
PySide2.QtWidgets.QSplashScreen(parent[, pixmap=QPixmap()[, f=Qt.WindowFlags()]])
Note
This constructor is deprecated.
PySide2.QtWidgets.QSplashScreen([pixmap=QPixmap()[, f=Qt.WindowFlags()]])
- param f:
WindowFlags- param parent:
- param screen:
- param pixmap:
Construct a splash screen that will display the
pixmap.There should be no need to set the widget flags,
f, except perhapsWindowStaysOnTopHint.
- PySide2.QtWidgets.QSplashScreen.clearMessage()露
Removes the message being displayed on the splash screen
See also
- PySide2.QtWidgets.QSplashScreen.drawContents(painter)露
- Parameters:
painter 鈥
PySide2.QtGui.QPainter
Draw the contents of the splash screen using painter
painter. The default implementation draws the message passed byshowMessage(). Reimplement this function if you want to do your own drawing on the splash screen.
- PySide2.QtWidgets.QSplashScreen.finish(w)露
- Parameters:
Makes the splash screen wait until the widget
mainWinis displayed before callingclose()on itself.
- PySide2.QtWidgets.QSplashScreen.message()露
- Return type:
str
Returns the message that is currently displayed on the splash screen.
See also
- PySide2.QtWidgets.QSplashScreen.messageChanged(message)露
- Parameters:
message 鈥 str
- PySide2.QtWidgets.QSplashScreen.pixmap()露
- Return type:
Returns the pixmap that is used in the splash screen. The image does not have any of the text drawn by
showMessage()calls.See also
- PySide2.QtWidgets.QSplashScreen.setPixmap(pixmap)露
- Parameters:
pixmap 鈥
PySide2.QtGui.QPixmap
Sets the pixmap that will be used as the splash screen鈥檚 image to
pixmap.See also
- PySide2.QtWidgets.QSplashScreen.showMessage(message[, alignment=Qt.AlignLeft[, color=Qt.black]])露
- Parameters:
message 鈥 str
alignment 鈥 int
color 鈥
PySide2.QtGui.QColor
Draws the
messagetext onto the splash screen with colorcolorand aligns the text according to the flags inalignment. This function callsrepaint()to make sure the splash screen is repainted immediately. As a result the message is kept up to date with what your application is doing (e.g. loading files).See also
AlignmentclearMessage()message()
漏 2022 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 the GNU 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.