gpt4 book ai didi

python - 未显示来自另一个 QDialog 的 QDialog

转载 作者:太空宇宙 更新时间:2023-11-04 02:44:37 25 4
gpt4 key购买 nike

在我的主应用程序中,我打开了一个 QDialog,我想从这个 QDialog 打开/显示另一个。它没有显示第二个带有焦点的对话框,而是出现在我的主应用程序后面并被阻止/禁用,我无法使用它。每个表单都在一个单独的文件中:

在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)
...

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

最佳答案

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

你可以看看documentation QDialog 以查看如何更改模态模式。您还可以使用 modality enum 更改模态窗口的行为。 .

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

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

关于python - 未显示来自另一个 QDialog 的 QDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45505777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com