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

QWidget::restoreGeometry does not work as documented.

    XMLWordPrintable

Details

    • Windows
    • 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

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

          Activity

            People

              axelspoerl Axel Spoerl
              xda XDA XDA
              Votes:
              6 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes