Hi!
I've got MainWindow form build in Qt Designer. I want to implement some events for this window. I tried to reimplement closeEvent method using code like this:
from PySide import QtCore
from PySide import QtGui
from PySide import QtUiTools
import sys
def __init__(self, parent=None):
super(TestWin, self).__init__(parent)
uiFile
= QtCore.
QFile('testForm.ui') uiFile.
open(QtCore.
QFile.
ReadOnly)
self.mainWindow = loader.load(uiFile)
self.mainWindow.show()
self.mainWindow.closeEvent = self.myCloseEvent
def myCloseEvent(self, event):
print 'Close'
event.accept()
if __name__ == '__main__':
testApp = TestWin()
app.exec_()
from PySide import QtCore
from PySide import QtGui
from PySide import QtUiTools
import sys
class TestWin(QtGui.QMainWindow):
def __init__(self, parent=None):
super(TestWin, self).__init__(parent)
loader = QtUiTools.QUiLoader()
uiFile = QtCore.QFile('testForm.ui')
uiFile.open(QtCore.QFile.ReadOnly)
self.mainWindow = loader.load(uiFile)
self.mainWindow.show()
self.mainWindow.closeEvent = self.myCloseEvent
def myCloseEvent(self, event):
print 'Close'
event.accept()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
testApp = TestWin()
app.exec_()
To copy to clipboard, switch view to plain text mode
but this code doesn't work. How should I reimplement methods for Qt Designer forms ?
Thanks,
Marcin
Bookmarks