PySide:隐藏对话框会破坏dialog.exec_()

时间:2013-05-21 18:20:41

标签: python dialog pyside

在我的项目中,我必须向人们显示一个可以接受或打开另一个对话框的对话框。 我通过dialog.exec_()的使用开始对话,这也可以捕捉QtGui.QDialog.Accepted并在它之后做一些好事。

当第一个对话框打开第二个对话框时,我尝试使用self.hide()隐藏第一个对话框,当第二个对话框收到self.show()时,我会使用QtGui.QDialog.Accepted再次显示该对话框。 这样可以正常工作,但在此之后,第一个窗口的“接受”按钮不会返回QtGui.QDialog.Accepted

之类的内容

问题是,在打开第二个窗口时使用self.hide()self.show()之前一切正常。保留隐藏选项使其无故障地工作。

如何在不破坏窗口被接受时我需要知道的dialog.exec_()的情况下隐藏和显示对话框?

1 个答案:

答案 0 :(得分:0)

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