PDA

View Full Version : [SOLVED] [PyQt4] Want to connect a window's close button



dodle
May 11th, 2009, 12:30 AM
I want to connect the "x" button on my program's main window with a function that I created. I know how to do it in wxPython:

self.Bind(wx.EVT_CLOSE, self.onQuit)


But I can't figure out how to do it with PyQt4. I've tried:

self.connect(self, Qt.SIGNAL('quit()'), self.onQuit)
and

self.connect(self, Qt.SIGNAL('destroyed()'), self.onQuit)

dodle
May 11th, 2009, 01:17 AM
Figured it out with the help of http://zetcode.com/tutorials/pyqt4/firstprograms/

I just had to rename my function to "closeEvent", and then connect to it:

self.connect(self, Qt.SIGNAL('triggered()'), self.closeEvent

def closeEvent(self, event):
print "Closing"
self.destory()

fifth
May 11th, 2009, 12:59 PM
Figured it out with the help of http://zetcode.com/tutorials/pyqt4/firstprograms/

I just had to rename my function to "closeEvent", and then connect to it:

self.connect(self, Qt.SIGNAL('triggered()'), self.closeEvent

def closeEvent(self, event):
print "Closing"
self.destory()

self.destroy() might give you some problems, although maybe not visibly if its the last application window your closing. You might be better off using;


self.deleteLater()

Qt will then destroy the object when its no longer being used.

tollboy
July 3rd, 2009, 12:37 PM
thanxs i was searching for this [:)]