3

I would like to display a message before QGIS close. But I can't intercept the closeEvent of the main window from my plugin. I've tested this code which doesn't work.

# Main method
QgsApplication.instance().closeEvent = self.mainWindowCloseEvent

def mainWindowCloseEvent(self, event) :
    # displaying message...
    event.ignore()

4
  • 1
    The QgsApplication class inherits from QApplication which has the signal aboutToQuit(). Perhaps you can make that work for you?
    – Ben W
    Commented Jan 20, 2021 at 12:59
  • 1
    As @BenW suggested, using aboutToQuit might do the trick, maybe with something like: QgsApplication.instance().aboutToQuit.connect(mainWindowCloseEvent), similar to how you connect qt signals to function in the plugin.
    – Dror Bogin
    Commented Jan 20, 2021 at 13:04
  • Thanks for your responses. It doesn't work, i can't cancel the event or display a message. The documentation says " Note that no user interaction is possible in this state."
    – TrsBar
    Commented Jan 20, 2021 at 13:39
  • I needed something like that before, but I couldn't find any solution. gis.stackexchange.com/questions/162443/… Commented Jan 21, 2021 at 7:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.