内容表

上一话题

QSpinBox

下一话题

QSplitter

QSplashScreen

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

Inheritance diagram of PySide2.QtWidgets.QSplashScreen

概要

函数

虚函数

信号

详细描述

闪屏是应用程序启动时,通常显示的 Widget。闪屏常用于长启动时间的应用程序 (如:数据库或花时间建立连接的网络应用程序),为用户提供应用程序加载反馈。

闪屏出现在屏幕的中心。它可能是有用的,添加 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:

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()
											

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:

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

QSplashScreen(parent[, pixmap=QPixmap()[, f=Qt.WindowFlags()]])

注意

This constructor is deprecated.

QSplashScreen([pixmap=QPixmap()[, f=Qt.WindowFlags()]])

param f

WindowFlags

param parent

QWidget

param screen

QScreen

param pixmap

QPixmap

构造闪屏显示 pixmap .

应该不需要设置 Widget 标志, f ,或许除了 WindowStaysOnTopHint .

PySide2.QtWidgets.QSplashScreen. clearMessage ( )

移除在闪屏上显示的消息

另请参阅

showMessage()

PySide2.QtWidgets.QSplashScreen. drawContents ( painter )
参数

painter QPainter

绘制闪屏的内容,使用描绘器 painter 。默认实现绘制传递的消息,通过 showMessage() . Reimplement this function if you want to do your own drawing on the splash screen.

PySide2.QtWidgets.QSplashScreen. finish ( w )
参数

w QWidget

使闪屏等待,直到小部件 mainWin is displayed before calling close() on itself.

PySide2.QtWidgets.QSplashScreen. message ( )
返回类型

unicode

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

PySide2.QtWidgets.QSplashScreen. messageChanged ( message )
参数

message – unicode

PySide2.QtWidgets.QSplashScreen. pixmap ( )
返回类型

QPixmap

Returns the pixmap that is used in the splash screen. The image does not have any of the text drawn by showMessage() 调用。

另请参阅

setPixmap()

PySide2.QtWidgets.QSplashScreen. setPixmap ( pixmap )
参数

pixmap QPixmap

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

另请参阅

pixmap()

PySide2.QtWidgets.QSplashScreen. showMessage ( message [ , alignment=Qt.AlignLeft [ , color=Qt.black ] ] )
参数
  • message – unicode

  • alignment int

  • color QColor

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).

另请参阅

Alignment clearMessage() message()