亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 ui 對話框導入中阻止啟動屏幕

從 ui 對話框導入中阻止啟動屏幕

揚帆大魚 2022-04-23 16:56:40
我制作了一個大型應用程序,在主應用程序(主循環)中導入了大量對話框。這些對話框導入時間很長,所以我做了一個啟動畫面,但主循環中的啟動畫面當然被長時間導入阻止了。認為我沒有得到的是我不能在主循環中移動導入,因為我從創建 ui 的類中得到一個錯誤,當代碼從解釋器檢查時運行。這里是示例代碼:from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupportfrom PyQt5.QtWidgets import QDialog,QWidget,QApplication, QInputDialog, QLineEdit, QFileDialog,QProgressDialog, QMainWindow, QFrame,QSplashScreenfrom PyQt5.QtCore import QThread , pyqtSignal,Qtfrom PyQt5.QtGui import QIcon,QPainter,QPixmap#here the slow import dialogsfrom ui import Ui_MainWindow,HoverButtonfrom dialog1 import Ui_Dialogfrom dialog2 import Ui_Dialog2from dialog3 import Ui_dialog3from dialog4 import Ui_Dialog4from dialog5 import Ui_dialog5from dialog6 import Ui_dialog6#....... and so on###after class methods###class Dialog1(QtWidgets.QDialog,Ui_Dialog):                                #fuel button prompt dialog for inputs    def __init__(self,parent=None):        super(Dialog1, self).__init__(parent)        self.setupUi(self)class Dialog2(QtWidgets.QDialog,Ui_Dialog2):                               #all errors dialog    def __init__(self,parent=None):        super(Dialog2, self).__init__(parent)        self.setupUi(self)class Dialog3(QtWidgets.QDialog,Ui_dialog3):                               #that might take a while dialog    def __init__(self,parent=None):        super(Dialog3, self).__init__(parent)        self.setupUi(self)class Dialog4(QtWidgets.QDialog,Ui_Dialog4):                               #input gross weight dialog    def __init__(self,parent=None):        super(Dialog4, self).__init__(parent)        self.setupUi(self)class Dialog5(QtWidgets.QDialog,Ui_dialog5):                               #map viewer specifications dialog    def __init__(self,parent=None):        super(Dialog5, self).__init__(parent)        self.setupUi(self)
查看完整描述

1 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

假設唯一的問題是大量對話,而不是每個對話本身都有一個消耗大量時間的任務,因此可能的選擇是每 T ms 加載每個對話,以便在過渡時間內 QSplashScreen 正常工作。


# ...

###MAIN GUI###

class mainProgram(QtWidgets.QMainWindow, Ui_MainWindow):

    loadFinished = QtCore.pyqtSignal()


    def __init__(self, parent=None):

        super(mainProgram, self).__init__(parent)

        self.setupUi(self)

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)


        self._T_dialogs = iter(

            enumerate((Dialog1, Dialog2, Dialog3, Dialog4, Dialog5, Dialog6))

        )


        self._timer = QtCore.QTimer(self, timeout=self.create_dialogs, interval=100)

        self._timer.start()


    @QtCore.pyqtSlot()

    def create_dialogs(self):

        try:

            i, T = next(self._T_dialogs)

            w = T(self)

            setattr(self, "dialog{}".format(i), w)

        except StopIteration:

            self._timer.stop()

            self.showMaximized()

            self.loadFinished.emit()



if __name__ == "__main__":

    import sys


    app = QtWidgets.QApplication(sys.argv)

    splash_pix = QtGui.QPixmap("loading.jpg")

    splash_pix.scaled(200, 400, QtCore.Qt.KeepAspectRatio)

    splash = QtWidgets.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint)

    splash.setMask(splash_pix.mask())

    splash.show()

    nextGui = mainProgram()

    nextGui.loadFinished.connect(splash.close)

    sys.exit(app.exec_())



查看完整回答
反對 回復 2022-04-23
  • 1 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號