I have been trying to override the Windows 'X' button close to save some data with no luck. I am using PyQT 4.7.4 and Python 2.7 on Windows XP. I used Qt Designer to create the following class for the main window. This is part of the class code:
class Ui_MainWin(object):
def setupUi(self, MainWin):
MainWin.setObjectName("MainWin")
MainWin.resize(511, 362)
In another Python module, I setup the window with the following code:
app = QtGui.QApplication(sys.argv)
MainWin = QtGui.QMainWindow()
ui = Ui_MainWin()
ui.setupUi(MainWin)
I've searched on-line on how to override the Window's 'X' button and seen in several examples where people use the closeEvent in their window class that sets up the window:
def closeEvent(self,event):
print "in routine"
When I use this code inside my class, it doesn't capture the window closing. I then thought I needed to try to connect the close event to the function (signal to slot) and use this connect statement:
self.centralwidget.connect(self.menubar.closeEvent (),QtCore.SIGNAL('triggered()'), self.closeEvent())
I get the error:
closeEvent(QCloseEvent), not enough arguments
I have the following questions:
1. I am defining the function incorrectly to capture the closeEvent()?
2. Do I need a connect statement?
I have been using PyQt for only 6 weeks.
Bookmarks