Message 1 of 3

Not applicable
07-12-2018
02:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I can't create a ui from a designer file and then have closeEvent called when I close the ui. I think I need to load the ui file differently, but I can't figure out how to do that in PySide. I've tried many variations on this, and no matter what I do, the closeEvent doesn't seem to get sent when I close the window (clicking on the x) when using the ui file. What am I missing?
Here's my ui file, (test.ui)
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Dialog</class> <widget class="QDialog" name="Dialog"> <property name="geometry"> <rect> <width>400</width> <height>300</height> </rect> </property> </widget> </ui>
And here's my code:
class testClass(QtWidgets.QDialog): def __init__(self, useUiFile): super(TestClass, self).__init__() if useUiFile: self.ui = QtUiTools.QUiLoader().load("test.ui") self.ui.show() else: self.show() def closeEvent(self, event): print("closeEvent!!!!!")
If I don't use the UI file, my closeEvent gets called when I close the window:
ui = testClass(0) # calls closeEvent when closed
If I use the UI file, a closeEvent doesn't seem to be generated:
ui = testClass(1) # doesn't call closeEvent when closed
Solved! Go to Solution.