[Maya][PySide] Triggering close/hide event when a DockControl is closed

I am trying to trigger a QSettings Save when my Qt GUI parented to a dockControl is closed. However, it seems that clicking the little “X” to close the GUI only hides the GUI, it doesn’t close it, so the QSettings don’t get saved.

Anyone have an advice for how to hook into the callback that is called when a dockControl’s close button is clicked?

I haven’t tried this, but my first thought would be to try overriding hideEvent and trigger the QSettings save from in there.

to fix this problem I had to hook up a function to VisibilityChangedCommand like so:

    
    def __init__(self, parent=ui.getMayaMainWindow):
        # stuff

        self.dockCtrl = cmds.dockControl(aa=['right', 'left'], a='right', 
                                         content=self.objectName(), w=370, 
                                         vcc=lambda *args: self.saveSettingsWhenHidden(),
                                         label='My Tool Box')

    def saveSettingsWhenHidden(self):
        
        if cmds.dockControl(self.dockCtrl, q=True, io=True):
            self.writeSettings()

    def closeEvent(self, event):
        
        self.writeSettings()
        cmds.deleteUI(self.dockCtrl)
        try:
            QtGui.QWidget.closeEvent(self, event)
        except: pass

I found this link to be helpful:

http://mayastation.typepad.com/maya-station/2010/08/dockcontrol-part-2-adv-usage-1.html