0

I'm writing a plugin in python for an app that use Qt as framework. I would like to intercept the event closeEvent of the QMainWindow to show an alert if a background process is running. I have access to the QApplication and QMainWindow object only. Is there a way to override the closeEvent like (doesn't work) (or a signal) ? :

mainWindow.closeEvent = self.onCloseEvent

def onCloseEvent(self, event) :
    if (self.hasSubProcess()) : 
        event.ignore()
    else :
        event.accept()
TrsBar
  • 139
  • 9
  • Does this answer your question? [PySide / PyQt detect if user trying to close window](https://stackoverflow.com/questions/9249500/pyside-pyqt-detect-if-user-trying-to-close-window) – Alejandro Condori Feb 22 '21 at 13:27
  • That depends on the program (is it Maya?); when you say "use Qt as framework" does it mean that it's written in PyQt or that you just know that it uses Qt and it's actually a C++ program? – musicamante Feb 22 '21 at 13:28
  • You might be able to [install an event-filter](https://doc.qt.io/qt-5/qobject.html#installEventFilter) on the QApplication or QMainWindow to detect the close-event. – ekhumoro Feb 22 '21 at 13:41
  • @musicamante It's Qgis. It's a C++ program and it has sip to bind python. – TrsBar Feb 23 '21 at 17:32

0 Answers0