How does one properly capture the close event coming out of a PySide QtUiTools.QUiLoader() setup?
I can get the instanced class to connect to widgets and everything else, but I am not sure how to intercept the signals in this setup.
Ideally, I want all close calls to pass through my closeEvent (obviously) so that I can ensure that it's safe to close the window. But since my self.closeEvent() is tied to my View(QtWidgets.QMainWindow) and not the self._qt.closeEvent(), I don't know how to get to the self._qt.closeEvent() method to override it in this case.
Or is there a better way to set this up to capture those window events?
# Compatible enough with Pyside 2
from PySide import QtGui as QtWidgets
from PySide import QtUiTools
from PySide import QtCore
class View(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(View, self).__init__(parent=parent)
self.setup()
def closeEvent(self, event):
# Do things
event.accept()
def setup(self):
loader = QtUiTools.QUiLoader()
fy = QtCore.QFile('example.ui')
fy.open(QtCore.QFile.ReadOnly)
self._qt = loader.load(fy, self)
fy.close()
self._qt.pCanceled.clicked(self._qt.close)
Doesn't apply:
PySide / PyQt detect if user trying to close window
Close, but PySide doesn't use PyQt's uic and appears to run differently (and didn't work):