Hi Everyone,

I have a question with the closeEvent method. If I use self.accept() in the close event I get what I am expecting. If I use event.accept() the window did not execute. Why is event.accept() not working? See below for the example.

After the second window closes I was expecting the print statement to print. Am I not understanding how exec_() works?

Qt Code:
  1. class Tool1(QtGui.QDialog, ui_tool_1_1.Ui_tool1_1_Dialog):
  2. """Tool1 dialog"""
  3.  
  4. # class Initialization
  5. def __init__(self, parent=None):
  6.  
  7. # python super so script does not need to call the methods by name.
  8. super(Tool1, self).__init__(parent)
  9. self.setupUi(self)
  10.  
  11. # Push button to open a new gui.
  12. self.add_evt_pushButton.clicked.connect(self.addEvt)
  13.  
  14. def addEvt(self):
  15. test = AppField(parent=self)
  16. if test.exec_():
  17. print"hello"
  18.  
  19.  
  20. class AppField(QtGui.QDialog, ui_app_field.Ui_AppFieldDialog):
  21. """
  22. Tool 2.
  23. """
  24. # class Initialization
  25. def __init__(self, parent=None):
  26. super(AppField, self).__init__(parent)
  27. self.setupUi(self)
  28.  
  29. # connection to okay button.
  30. self.ok_pushButton.clicked.connect(self.okay_button)
  31.  
  32. def okay_button(self):
  33. """
  34. handles the ok push button.
  35. """
  36. self.close()
  37.  
  38. def closeEvent(self, event):
  39. if QtGui.QMessageBox.question(self, "warning", "do you want to close",
  40. QtGui.QMessageBox.Yes|QtGui.QMessageBox.No) == QtGui.QMessageBox.No:
  41. event.ignore()
  42. else:
  43. event.accept()
To copy to clipboard, switch view to plain text mode