处理多个PyQt文件的正确方法?

时间:2017-12-28 07:11:46

标签: python qt4 pyqt4

我为多个表单设计了UI,例如登录页面,仪表板页面,设置页面。这些文件的代码位于login.py dashboard.py和space_storage.py中。现在我想将这些表格相互连接起来。为此,我创建了一个新文件main.py并导入了这些模块。

    from PyQt4 import QtGui, QtCore
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *
    import sys
    import login, dashboard2, settings, space_storage

    class LoginScreen(QtGui.QDialog, login.Ui_Dialog):
        def __init__(self):
            super(self.__class__, self).__init__()
            self.center()
            self.setupUi(self)
            self.login_btn.clicked.connect(self.loginCheck)

        def dashboardWindowShow(self):
            self.welcomeWindow = QtGui.QMainWindow()
            self.ui = dashboard()

            self.ui.setupUi(self.welcomeWindow)
            self.ui.center()
            self.welcomeWindow.show()

            self.hide()

        def spaceStorageShow(self):
            self.welcomeWindow2 = QtGui.QWidget()
            self.ui2 = SpaceStorage()

            self.ui2.setupUi(self.welcomeWindow2)
            self.ui2.center()
            self.welcomeWindow2.show()

        def center(self):
            screen = QtGui.QDesktopWidget().screenGeometry()
            size = self.geometry()
            self.move((screen.width() - size.width()) / 2,
                      (screen.height() - size.height()) / 2)


        def showMessageBox(self,title,message):
            msgBox = QtGui.QMessageBox()
            msgBox.setIcon(QtGui.QMessageBox.Warning)
            msgBox.setWindowTitle(title)
            msgBox.setText(message)
            msgBox.setStandardButtons(QtGui.QMessageBox.Ok)
            msgBox.exec_()

        def loginCheck(self):
            username = self.uname_lineEdit.text()
            password = self.pass_lineEdit.text()
            if (username == 'a' and
                    password == 'a'):
                self.dashboardWindowShow()
                self.spaceStorageShow()

            else:
                # print("User Not Found !")
                self.showMessageBox('Warning', 'Invalid Username And Password')    

    class dashboard(QtGui.QMainWindow, dashboard2.Ui_MainWindow):
            def __init__(self):
                super(self.__class__, self).__init__()
                self.setupUi(self)
                self.comboBox.currentIndexChanged[int].connect(self.comboBoxActions)
            def comboBoxActions(self, value):
                print(value)
def main():
    app = QtGui.QApplication(sys.argv)
    form = LoginScreen()
    form.show()                         # Show the form
    app.exec_()                         # and execute the app

现在问题是每当我从LoginScreen调用dashboardWindowShow()时,它都会从dashboard2显示GUI。但是我在仪表板类(comboBoxActions)中添加的自定义功能并不起作用。

如果我直接从main方法运行form=dashboard(),它就能完美运行。

我不知道这里有什么问题?

0 个答案:

没有答案