QSplashScreenwidget provides a splash screen that can be shown during application startup. 更多 …
def
drawContents
(painter)
def
clearMessage
()
def
showMessage
(message[, alignment=Qt.AlignLeft[, color=Qt.black]])
def
messageChanged
(message)
闪屏是应用程序启动时,通常显示的 Widget。闪屏常用于长启动时间的应用程序 (如:数据库或花时间建立连接的网络应用程序),为用户提供应用程序加载反馈。
闪屏出现在屏幕的中心。它可能是有用的,添加
WindowStaysOnTopHintto 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()
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();
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
- param screen
QScreen- param pixmap
QPixmap
构造闪屏显示
pixmap
.
应该不需要设置 Widget 标志,
f
,或许除了
WindowStaysOnTopHint
.
PySide2.QtWidgets.QSplashScreen.
clearMessage
(
)
¶
移除在闪屏上显示的消息
另请参阅
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()
调用。
另请参阅
PySide2.QtWidgets.QSplashScreen.
setPixmap
(
pixmap
)
¶
pixmap
–
QPixmap
Sets the pixmap that will be used as the splash screen’s image to
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()