在我的项目中,我必须向人们展示一个可以接受或打开另一个对话框的对话框。我通过使用dialog.exec_()
来启动对话框,这也使得捕获QtGui.QDialog.Accepted
并在它之后做一些很好的事情成为可能。
当第一个对话框打开第二个对话框时,我尝试用self.hide()
隐藏第一个对话框,当第二个对话框收到QtGui.QDialog.Accepted
时,我用self.show()
再次显示它。这可以很好地工作,但在此之后,第一个窗口的accept按钮不会返回任何类似QtGui.QDialog.Accepted
的内容
问题是,在打开第二个窗口时使用self.hide()
和self.show()
之前,它工作得很好。去掉隐藏选项可以让它毫无瑕疵地工作。
如何在不破坏当窗口被接受时需要知道的dialog.exec_()
的情况下隐藏和显示对话框?
发布于 2013-05-25 14:50:01
Abarnert的回答让我重新思考了我的对话框设计。首先,我再次尝试使用非模式对话框,但这并不一致。
最后,我做了一个模式对话框序列,效果非常好!我首先启动第一个对话框,当它被接受时,它继续,但是当它被拒绝时,出现另一个只能被接受的对话框。接受第二个对话框后,将再次执行第一个对话框。
通过使用while循环,您可以轻松地管理以下内容:
self.notification = firstDialog(self) #custom dialog class
self.notification2 = secondDialog(self) #second custom dialog class
while True:
self.notification.show()
if self.notification.exec_() == QtGui.QDialog.Accepted:
break
else: #in case of rejection (the only other option in this dialog)
self.notification2.show()
if self.notification2.exec_() == QtGui.QDialog.Accepted:
continue
self.startFunction() #start what should happen after people accept the dialog
https://stackoverflow.com/questions/16676851
复制相似问题