[PyQt] restoreState not working for QDockWidgets
Hans-Peter Jansen
hpj at urpla.net
Thu Nov 12 10:17:41 GMT 2009
On Thursday 12 November 2009, 09:08:09 Brian Zambrano 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)
Brian, do you expect us to build a runable script from your artefacts?
Please keep in mind, that due to the unlimited permutations of OS, Qt, sip,
and PyQt versions, it's unpossible to estimate the behavior of even the
simplest code fragments in all circumstances (apart from: QWidget.show()
will most likely *not* format your harddisk).
Therefor, it's a long standing best practice here to provide a self
contained minimum example, the exploits the issue.
BTW, in my case, 70% of all issues vanish during this exercise, e.g. it's
mostly a "RTFM" or "between keyboard and chair problem"..., another > 20%
by looking into Qt itself.
I estimate the portion of real sip and/or PyQt issues below 3%.
Pete
> 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