未显示来自另一个 QDialog 的 QDialog

A QDialog from another QDialog not shown

在我的主应用程序中,我打开了一个 QDialog,我想从这个 QDialog open/show 另一个。它没有显示第二个带有焦点的对话框,而是出现在我的主应用程序后面并且是 blocked/disabled 并且我不能不使用它。每个表格都在一个单独的文件中:

在mainform.py中:

form_gui = uic.loadUiType("mainform.ui")[0] # Load the UI
class MainForm(QtGui.QMainWindow, form_gui):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent) 
        self.btnOpenForm1.clicked.connect(self.showFirstDialog)
    ...
    def showFirstDialog(self):
        browser1 = UI_Form1(self)
        browser1.setWindowTitle('UI_Form1')
        browser1.show()
    ... 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    myapp = MVSGUI()
    myapp.show()
    sys.exit(app.exec_())

在文件中 UI_Form1.py:

form_gui = uic.loadUiType("uiform1.ui")[0] # Load the UI
class UI_Form1(QtGui.QDialog, form_gui):
    def __init__(self, parent):
        super(UI_Form1, self).__init__(parent)
        self.btnOpenForm2.clicked.connect(self.showSecondDialog)
    ...
    def showSecondDialog(self):
        browser2 = UI_Form2(self)
        browser2.setWindowTitle('UI_Form2')
        browser2.show() 
    ...

在文件中 UI_Form2.py:

form_gui = uic.loadUiType("uiform2.ui")[0] # Load the UI
class UI_Form2(QtGui.QDialog, form_gui):
    def __init__(self, parent):
        super(UI_Form2, self).__init__(parent)
    ...

可能很容易猜到哪里出了问题,但我找不到解决方法。

QDialogs 可以在模态和无模态模式下创建。如果您想同时使用多个,请确保将它们设为无模式。

您可以查看 QDialog 的 documentation 以了解如何更改模态模式。 您还可以使用 modality enum.

更改模式 window 的行为

还要确保为正确的任务使用正确的工具,documentation 指出:

A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user.