I have a Qt program and currently I use the Qsettings.saveGeometry() and Qsettings.saveState() functions to allow the program to restore the layout that the user set in the previous session. However not all geometry is saved, only the main window and not the children especially floating position of docked windows and table column widths within docked windows.
This thread seems to attempt to provide an answer (but in C++ and not python): http://www.qtforum.org/article/38362/save-geometry-of-all-widgets-recursively.html
I am coding in Python and my C++ is not very good so I can't fully follow the example at the above link.
Does anyone know if that approach works?
In general is it possible to use Qsettings to store floating position of docked windows and table column widths?
Could anyone suggest a python/pyside based solution?
Many thanks.
Ron
As three_pineapples pointed out, iterating over all widgets is not a good idea since things you wouldn't want to save, (buttons, label) are also derived from
QWidget
.I'd suggest to simply give meaningful name to each floating docked-window:
Then you can iterate against object names instead seeking widgets from child object. To create a
QSettings
group for that particular window:You can make this easier by using common pattern for names, e.g.
floatingMain
,floatingTools
,floatingMenu
.Ok guys. Here is the answer. There is a bug in Qt. When the main window is maximised and the QdocWidget's are docked (not floating) then the floating position is not saved.
This code is a simple workaround.
to save:
to restore: