Fix QSettings documentation

QMainWindow::saveGeometry()/restoreGeometry() should be used
to save and restore geometries instead of saving pos/size
since it also works in multiscreen settings.

Pick-to: 6.1
Change-Id: I27cc5ec13e69266367f035796e208d214f84b043
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Friedemann Kleint 2021-06-01 09:53:18 +02:00
parent 253d97cce6
commit c59fbf576d

View File

@ -152,8 +152,7 @@ void MainWindow::writeSettings()
QSettings settings("Moose Soft", "Clipper");
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.setValue("geometry", saveGeometry());
settings.endGroup();
}
//! [16]
@ -164,8 +163,11 @@ void MainWindow::readSettings()
QSettings settings("Moose Soft", "Clipper");
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(400, 400)).toSize());
move(settings.value("pos", QPoint(200, 200)).toPoint());
const auto geometry = settings.value("geometry", QByteArray()).toByteArray();
if (geometry.isEmpty())
setGeometry(200, 200, 400, 400);
else
restoreGeometry(geometry)
settings.endGroup();
}
//! [17]