[Qt-interest] restoreGeometry of QMdiSubWindow

RZ rz at univie.ac.at
Tue Aug 11 22:22:02 CEST 2009


Thx for the hints,

I'll post the solution so others might find (I remember stumbling over 
it in Qt3 and thought things might have changed):

First, restoring of geometry can not be done in the c'tor. And that's 
because with this mdi stuff - don't ask me why - you need to refer to 
the _parentWidget_.

So correct is:

QSettings settings("MyCompany", "MyApp");
settings.setValue("geometry", parentWidget()->saveGeometry());

QSettings settings("MyCompany", "MyApp");
parentWidget()->restoreGeometry(settings.value("geometry").toByteArray());

The problem is that parentWidget() returned NULL when called in the 
c'tor ?!? - so I call it from outside after show() ...

Regards,

Roland

> Hi all,
> 
> I want my mdi sub windows to appear at the same location and with the 
> same size they were closed with. To achieve that I just copied code out 
> of the Qt Assistant docs namely
> 
> QSettings settings("MyCompany", "MyApp");
> settings.setValue("geometry", saveGeometry());
> 
> in the closeEvent and
> 
> QSettings settings("MyCompany", "MyApp");
> restoreGeometry(settings.value("myWidget/geometry").toByteArray());
> 
> in the c'tor of the mdiChild. Although the settings get stored this does 
> not work (can very easily be checked with the mainwindows/mdi example).
> 
> While this usualy works is this a bug? Or did I miss some special 
> features of QMdi* ?!?
> 
> Regards,
> 
> RZ



More information about the Qt-interest-old mailing list