1

我试图在加载主窗口之前显示启动画面,但显示的是透明窗口而不是预期的图像。启动画面应该在 Dashboard 的导入和实例化加载后显示,这需要几秒钟,但图像仅在启动画面即将关闭时显示。下面是我的代码:

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QThread
from PyQt5.QtGui import QPixmap
from modules.video_opening.map.map import Map
import sys

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    splash_pic = QPixmap('splash.png')

    splash = QtWidgets.QSplashScreen(splash_pic, Qt.WindowStaysOnTopHint)
    splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
    splash.setEnabled(False)
    splash.setMask(splash_pic.mask())
    splash.showMessage("<h6>Loading...</h6>", Qt.AlignBottom | Qt.AlignRight, Qt.black)
    splash.show()
    app.processEvents()

    from modules.dashboard import Dashboard
    dashboard = Dashboard()
    splash.finish(dashboard)
    dashboard.show()

    app.exec_()
4

1 回答 1

0

这是目前对我有用的方法:添加一个循环 app.processEvents()

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QThread
from PyQt5.QtGui import QPixmap
from modules.video_opening.map.map import Map
import sys

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    splash_pic = QPixmap('splash.png')

    splash = QtWidgets.QSplashScreen(splash_pic, Qt.WindowStaysOnTopHint)
    splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
    splash.setEnabled(False)
    splash.setMask(splash_pic.mask())
    splash.showMessage("<h6>Loading...</h6>", Qt.AlignBottom | Qt.AlignRight, Qt.black)
    splash.show()

    for i in range(10000):
        app.processEvents()

    from modules.dashboard import Dashboard
    dashboard = Dashboard()
    splash.finish(dashboard)
    dashboard.show()

    app.exec_()
于 2019-12-10T09:22:48.543 回答