Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-77385

QWidget::restoreGeometry does not work as documented.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.1, 5.12.4, 5.13.0
    • Fix Version/s: None
    • Component/s: Widgets: Main Window
    • Labels:
      None
    • Platform/s:
      Windows

      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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              qt.team.quick.subscriptions Qt Quick and Widgets Team
              Reporter:
              xda XDA XDA
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes