带有线程的PySide2 SplashScreen

时间:2019-07-24 12:12:48

标签: python qthread pyside2

我在我的gui应用程序中添加了一个启动画面并通过线程调用,但是我的问题是在调用启动画面后即时加载了我的库或其他东西,但是此库或其他阻止主线程和启动画面的东西没有显示出来。 Qthread应该直接显示,还是我想错了?为什么会阻塞? 我的主要目标是直接启动启动画面并加载我的库或其他内容,而不会阻塞主线程。

我试图在调用启动画面后调用QApplication.processEvents(),但它也不起作用。

1- Main.py

app = QApplication()
splash = SplashScreen() # calling splashscreen
time.sleep(5) #blocking main thread

2-     SplashScreen.py

class SplashScreen(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        # Logo
        self.logo = QLabel()
        self.logo.setPixmap(QPixmap('ui/img/splash.gif'))
        self.logo.setAlignment(Qt.AlignHCenter | Qt.AlignBottom)

        # Loader
        self.loader = QLabel()
        loader_gif = QMovie('ui/img/loading.gif')
        loader_gif.start()
        self.loader.setMovie(loader_gif)
        self.loader.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

        layout = QVBoxLayout()
        layout.addWidget(self.logo)
        layout.addWidget(self.loader)
        self.setLayout(layout)
        self.setStyleSheet('background-color:#30393e')
        self.showFullScreen()


class SplashScreenThread(QThread):
    def __init__(self):
        QThread.__init__(self)

    def __del__(self):
        self.wait()

    def run(self):
        self.splash = SplashScreen()

0 个答案:

没有答案