[PyQt] restoreState not working for QDockWidgets

Phil Thompson phil at riverbankcomputing.com
Thu Nov 12 10:00:20 GMT 2009


This is not a self contained example, ie. one that we can run. How do you
know that these are the "relevant pieces"? By presenting us with a fragment
of code you are making the assumption that it must demonstrate the problem
- even though you have already said you don't know what the problem is.

One possible problem is that you are not giving the dock widget a name (see
the docs for QMainWindow.saveState()), but as your fragment has "# snip"
below the call to create it then who can tell?

Phil

On Thu, 12 Nov 2009 00:08:09 -0800, Brian Zambrano <brianz at gmail.com>
wrote:
> 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):
>         self.preferences.save()
> 
> 
> 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:
>             self.__main_window.resize(self.value('MainWindow/Size',
> QVariant(
>                         QSize(800, 600))).toSize())
> 
> self.__main_window.restoreState(self.value('State').toByteArray())
> 
>     def save(self):
>         self.setValue('MainWindow/Size',
> QVariant(self.__main_window.size()))
>         self.setValue('State', QVariant(self.__main_window.saveState()))
>         self.sync()
> 
> 
> 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
>>


More information about the PyQt mailing list