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?
Widgets are the primary elements for creating user interfaces in Qt. Widgets can display data and status information, receive user input, and provide a container for other widgets that should be grouped together. A widget that is not embedded in a parent widget is called a window.
The QLayoutItem class provides an abstract item that a QLayout manipulates. This is used by custom layouts. Pure virtual functions are provided to return information about the layout, including, sizeHint(), minimumSize(), maximumSize() and expanding().
The Qt layout system provides a simple and powerful way of automatically arranging child widgets within a widget to ensure that they make good use of the available space.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With