0

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

当第一个对话框打开第二个对话框时,我尝试隐藏第一个对话框,self.hide()self.show()在第二个对话框收到QtGui.QDialog.Accepted. 这工作正常,但在此之后第一个窗口的接受按钮不会返回类似QtGui.QDialog.Accepted

问题是它在使用self.hide()self.show()打开第二个窗口之前工作正常。将隐藏选项排除在外使其可以毫无缺陷地工作。

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

4

1 回答 1

0

Abarnert's answer made me think again about my dialog designs. First I tried it again with non-modal dialogs, but this was not consistent.

Finally I made a sequence of modal dialogs which works really great! I first start the first dialog, when its accepted it continues, however when its rejected another dialog comes up which only can get accepted. After you accept the second dialog the first dialog is executed again.

By using a while loop you can easily manage this:

    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
于 2013-05-25T14:50:01.413 回答