I would like to be able to intercept QGIS panels (QDockWidgets) closings.

I read the API online help but i don't clearly understand it.Is there any usable close signal linked with dockWidgets?

In a next step i would like to implement my own QDockWidgets with their own behaviour but ... how can i achieve this for existing integrated QGIS panels?

  • 1
    Have you tried the visibilityChanged or destroyed signal for your purposes? doc.qt.io/archives/qt-4.8/qdockwidget.html Also, what QGIS and Qt version? – Spacedman Apr 11 '18 at 13:31
  • I am on QGIS 2.18 so far. visibilityChanged seems to fit my needs. destroyed signal doesn't seem to give anything ... – snaileater Apr 11 '18 at 19:21

Are you trying to do so from the Python console, or are you actually working on QGIS source code?

In any case, QDockWidget does not emit a signal when closing. You should write your own class, derived from QDockWidget, and reimplement the closeEvent method, which is called whenever the widget is closed.

From there, you can emit a custom signal, if you need to notify the close event to the outside world.

  • yeah that's what i feared ... and no similar signal or inherited one ? does that mean there is nothing to do with the existing QGIS panels ? Maybe replace them with my customized one ? My aim is to develop a plug-in but i make some tests in the console. Thanks – snaileater Apr 11 '18 at 10:59
  • 1
    Not that I'm aware of. But if you already have a pointer to that panel you can check its status with the visible() property. – Sergio Monteleone Apr 11 '18 at 12:51

As S Monteleone pointed out there's no direct signal emitted by a QDockWidget when it's closed. However, there's still a close event fired. This means you can install a Qt event filter on the widget which intercepts close events and emits it's own signal to indicate that the dock was closed.

You'll need to do some reading on event filters - they are quite a powerful concept in Qt.

  • Thanks ! i'll work on this ... i'm playing with the visibilityChanged signal so far since destroyed signal doesn't seem to give anything visible ... – snaileater Apr 11 '18 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.