lukeQt
29th July 2015, 17:22
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?
class Tool1(QtGui.QDialog, ui_tool_1_1.Ui_tool1_1_Dialog):
"""Tool1 dialog"""
# class Initialization
def __init__(self, parent=None):
# python super so script does not need to call the methods by name.
super(Tool1, self).__init__(parent)
self.setupUi(self)
# Push button to open a new gui.
self.add_evt_pushButton.clicked.connect(self.addEv t)
def addEvt(self):
test = AppField(parent=self)
if test.exec_():
print"hello"
class AppField(QtGui.QDialog, ui_app_field.Ui_AppFieldDialog):
"""
Tool 2.
"""
# class Initialization
def __init__(self, parent=None):
super(AppField, self).__init__(parent)
self.setupUi(self)
# connection to okay button.
self.ok_pushButton.clicked.connect(self.okay_butto n)
def okay_button(self):
"""
handles the ok push button.
"""
self.close()
def closeEvent(self, event):
if QtGui.QMessageBox.question(self, "warning", "do you want to close",
QtGui.QMessageBox.Yes|QtGui.QMessageBox.No) == QtGui.QMessageBox.No:
event.ignore()
else:
event.accept()
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?
class Tool1(QtGui.QDialog, ui_tool_1_1.Ui_tool1_1_Dialog):
"""Tool1 dialog"""
# class Initialization
def __init__(self, parent=None):
# python super so script does not need to call the methods by name.
super(Tool1, self).__init__(parent)
self.setupUi(self)
# Push button to open a new gui.
self.add_evt_pushButton.clicked.connect(self.addEv t)
def addEvt(self):
test = AppField(parent=self)
if test.exec_():
print"hello"
class AppField(QtGui.QDialog, ui_app_field.Ui_AppFieldDialog):
"""
Tool 2.
"""
# class Initialization
def __init__(self, parent=None):
super(AppField, self).__init__(parent)
self.setupUi(self)
# connection to okay button.
self.ok_pushButton.clicked.connect(self.okay_butto n)
def okay_button(self):
"""
handles the ok push button.
"""
self.close()
def closeEvent(self, event):
if QtGui.QMessageBox.question(self, "warning", "do you want to close",
QtGui.QMessageBox.Yes|QtGui.QMessageBox.No) == QtGui.QMessageBox.No:
event.ignore()
else:
event.accept()