class QSplashScreen

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

Inheritance diagram of PySide6.QtWidgets.QSplashScreen

Synopsis

Methods

Virtual methods

Slots

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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 Qt::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 calls raise() 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:

if __name__ == "__main__":

    app = QApplication([])
    pixmap = QPixmap(":/splash.png")
    splash = QSplashScreen(pixmap)
    splash.show()
    app.processEvents()            ...

window = QMainWindow()
window.show()
splash.finish(window)
sys.exit(app.exec())

The user can hide the splash screen by clicking on it with the mouse. For mouse handling to work, call QApplication::processEvents() periodically during startup.

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")
QCoreApplication.processEvents()
... // Establishing connections
splash.showMessage("Established connections")
QCoreApplication.processEvents()

QSplashScreen supports this with the showMessage() 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() .

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:

screen = QGuiApplication.screens().at(1)
pixmap = QPixmap(":/splash.png")
splash = QSplashScreen(screen, pixmap)
splash.show()
__init__([pixmap=QPixmap()[, f=Qt.WindowFlags()]])
Parameters:

Construct a splash screen that will display the pixmap.

There should be no need to set the widget flags, f, except perhaps Qt::WindowStaysOnTopHint.

__init__(screen[, pixmap=QPixmap()[, f=Qt.WindowFlags()]])
Parameters:

This is an overloaded function.

This function allows you to specify the screen for your splashscreen. The typical use for this constructor is if you have multiple screens and prefer to have the splash screen on a different screen than your primary one. In that case pass the proper screen.

clearMessage()

Removes the message being displayed on the splash screen

See also

showMessage()

drawContents(painter)
Parameters:

painterQPainter

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

finish(w)
Parameters:

wQWidget

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

message()
Return type:

str

Returns the message that is currently displayed on the splash screen.

messageChanged(message)
Parameters:

message – str

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.

pixmap()
Return type:

QPixmap

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

setPixmap()

setPixmap(pixmap)
Parameters:

pixmapQPixmap

Sets the pixmap that will be used as the splash screen’s image to pixmap.

See also

pixmap()

showMessage(message[, alignment=Qt.AlignLeft[, color=Qt.black]])
Parameters:
  • message – str

  • alignment – int

  • colorQColor

Draws the message text onto the splash screen with color color and aligns the text according to the flags in alignment. This function calls repaint() 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).