[PyQt] saveState()/restoreState() of a nested QMainWindow

Hans-Peter Jansen hpj at urpla.net
Sun Jan 9 17:00:50 GMT 2011


On Wednesday 05 January 2011, 16:48:51 Bram Marien wrote:
> Hello everybody,
>
> I'm trying to use QSettings to save and restore the window
> configuration, and the size and position of its docking widgets to be
> more precise, in my application.
>
> My application is a normal QMainWindow (let's call this 'outer'),
> which has a QDockWidget, and a normal QWidget as its centralWidget.
> That centralWidget has a layout, and another QMainWindow as it's only
> widget (let's call this one 'inner').
>
> That 'inner' QMainWindow also has a dock widget.
>
> When I use QSettings to save and restore the state of the application
> (so : bother outer as inner QMainWindow), it  does it job perfectly
> for the 'outer' window : It restores both the location and the size
> of its docking widget. But the docking widget of the 'inner' window
> is not restored correctly : QSettings only recovers its location
> (Left/Bottom/...) but discards the stored size:  It seems to use the
> sizeHint rather than the user-preferred size.
>
> Am I doing something wrong with the QSettings usage?
> I know the 'QMainWindow in QMainWindow' is rather funky, but I'd
> really like the dock-concept in the inner central widget. And also :
> the inner QMainWindow may one day live on it's own, in stead of being
> a widget in another window...
>
> Here's some demo-code to show my problem: 
> http://pastebin.com/07NJJvDm
>
Your concept isn't sound. Qt expects just one QMainWindow in a single 
window, and ignoring this fact is just calling for trouble, and you're 
lucky that you just harvest slightly strange behavior, but that might 
change on every release of Qt.

You should create an internal interface, that allows your inner widget 
to register a dockwidget on its own in the outer QMainWindow, and you 
should be set.

Pete



More information about the PyQt mailing list