Petr
Petr

Reputation: 14505

How to store Qt gui layout and restore it

I have a Qt gui application that uses dock widgets and similar items, which user can adjust themselves.

I want the layout to stay on application restart. The application already has some functions to save and load user configuration, but I have no idea how would I store a layout (positions of docks, their size etc), neither how would I restore them.

Is there any easy way of doing this? Or do I have to check the size, position and location of every single element and store it separately?

Upvotes: 7

Views: 4382

Answers (1)

vahancho
vahancho

Reputation: 21240

For storing your dock windows layout you can use QMainWindow::saveState(int version) and QMainWindow::restoreState(const QByteArray &state, int version) in combination with QSettings class.

Example from Qt docs:

void MyMainWindow::closeEvent(QCloseEvent *event)
{
    QSettings settings("MyCompany", "MyApp");
    settings.setValue("geometry", saveGeometry());
    settings.setValue("windowState", saveState());
    QMainWindow::closeEvent(event);
}

Upvotes: 10

Related Questions