Question

I have a main window with some internal dockable windows. I can move, resize and redock those dockable windows. After close and reopen the program, I want the moves, sizes and redocking are kept. Any easy way to implement it? I think it will use settings. But which info should be saved in settings. And how to set a default layout of all these dock windows? When click an action button, it can be restored. Thanks.

Was it helpful?

Solution 2

Unfortunately, no, there is no built-in way to do this.

You'll need to loop through all your toolbars and dockable widgets and write their positions (and possibly their visibility) to a file. To restore, you can read that file and set your positions based on what you read.

The good news is that once you have such a system set up, making a default layout is easy - move all your widgets where you want them, then save your layout file, just like you do the user layouts above. You can even have multiple layouts, as long as they all get separate files.

OTHER TIPS

Check out QMainWindow::saveState/restoreState. It does exactly this.

To Save:

QSettings settings;
settings.setValue("DOCK_LOCATIONS",this->saveState(SOME_VERSION_DEFINE));

To Restore:

QSettings settings;
this->restoreState(settings.value("DOCK_LOCATIONS").toByteArray(),SOME_VERSION_DEFINE);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top