[PyQt] restoreState not working for QDockWidgets

Brian Zambrano brianz at gmail.com
Thu Nov 12 08:08:09 GMT 2009

The relevant pieces are basically this...have the main window save state
when it closes.  On startup, the main window passes itself to a QSettings
wrapper where the state should be restored.  The resize works just fine, the
dock widgets states do not work:

class MyMainWindow(QMainWindow):

    def __init__(self, etc.):
        # create a few QDockWidgets
        self.hud = HudDockWidget(self)
        # snip
        self.preferences = Preferences(self)

    def closeEvent(self, event):

class Preferences(QSettings):

    def __init__(self, mainwindow=None):
        QSettings.__init__(self, mainwindow)

        self.__main_window = mainwindow

        # Load some things on startup
        if self.__main_window is not None:
                        QSize(800, 600))).toSize())


    def save(self):
        self.setValue('State', QVariant(self.__main_window.saveState()))

class HudDockWidget(QDockWidget):
    "Dock widget which contains all of the HUD widgets"
    def __init__(self, parent=None):
        QDockWidget.__init__(self, 'Heads up Display', parent)

On Wed, Nov 11, 2009 at 4:04 PM, Hans-Peter Jansen <hpj at urpla.net> wrote:

> The usual "please provide a minimum self containing example" applies.
> Pete
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091112/37baf68d/attachment.html

More information about the PyQt mailing list