Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
5.12.1, 5.12.4, 5.13.0, 6.4.1
-
-
5edb71c6d (dev), fe4955c2f (6.5)
Description
We followed the documented method to restore the application state:
https://doc.qt.io/qt-5/restoring-geometry.html
and it is not working as documented.
https://doc.qt.io/qt-5/qwidget.html#restoreGeometry
"If the restored geometry is off-screen, it will be modified to be inside the available screen geometry."
Using Windows 10, if you have a second monitor to the right of your main monitor and place the application on it (it was not in the maximized state (haven't tested in the maximized state)), close the application so the state is saved on the second monitor, undock your laptop so only the main monitor is available, then re-open the application, it opens off-screen.
Note: this was not the case when the second monitor was above the main monitor.
Simplified Sample Code:
class MyTest : public QMainWindow { public: MyTest() : QMainWindow() { QSettings settings(QStringLiteral("org"), QStringLiteral("test")); settings.beginGroup(QStringLiteral("GROUP")); restoreGeometry(settings.value(QStringLiteral("GEOMETERY"), QByteArray()).toByteArray()); restoreState(settings.value(QStringLiteral("STATE")).toByteArray()); settings.endGroup(); } void closeEvent(QCloseEvent *event) override { QSettings settings(QStringLiteral("org"), QStringLiteral("test")); settings.beginGroup(QStringLiteral("GROUP")); settings.setValue(QStringLiteral("GEOMETERY"), saveGeometry()); settings.setValue(QStringLiteral("STATE"), saveState()); settings.endGroup(); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); MyTest mainWin; mainWin.show(); return QApplication::exec(); }
Attachments
Issue Links
- relates to
-
QTBUG-4397 QWidget::RestoreGeometry does not work if saveGeometry() is called while a widget is maximized [regression]
- Closed
-
QTBUG-69104 Dumb down the QWidget::restoreGeometry() logic
- Open
For Gerrit Dashboard: QTBUG-77385 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
448295,14 | Fix QWidget::restoreGeometry when restored geometry is off screen | dev | qt/qtbase | Status: MERGED | +2 | 0 |
449468,2 | Fix QWidget::restoreGeometry when restored geometry is off screen | 6.5 | qt/qtbase | Status: MERGED | +2 | 0 |
449469,2 | Fix QWidget::restoreGeometry when restored geometry is off screen | 6.4 | qt/qtbase | Status: ABANDONED | 0 | 0 |