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

saveGeometry/restoreGeometry do not work for fixed size windows on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.12, 6.2.3
    • None
    • macOS

    Description

      It is not possible to save and restore the window position of a fixed size window using saveGeometry() and restoreGeometry() on macOS.

      This behaviour can be reproduced using the following sample code:

        

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      #include <QMainWindow>
      class MainWindow : public QMainWindow
      {
       Q_OBJECT
      public:
       MainWindow(QWidget *parent = nullptr);
       ~MainWindow();
      protected:
       void closeEvent (QCloseEvent *e);
      };
      #endif // MAINWINDOW_H
      
      

        

      #include "mainwindow.h"
      #include <QSettings>
      #include <QDebug>
      
      MainWindow::MainWindow(QWidget *parent)
       : QMainWindow(parent)
      {
       setFixedSize(QSize(200, 100));
       QSettings s("myOrganization", "myApplication");
       restoreGeometry(s.value("geometry").toByteArray());
       show();
      }
      MainWindow::~MainWindow()
      {
      }
      
      void MainWindow::closeEvent(QCloseEvent *e)
      {
       qDebug() << isMaximized();
       QSettings s("myOrganization", "myApplication");
       s.setValue("geometry", saveGeometry());
       QMainWindow::closeEvent(e);
      }
      

       

       

      Under Windows everything works well.

      Interesting observation:
      When the closeEvent is received, the window claims to be maximized?!?

      The problem does not occur using Qt 5.6.3 or Qt 5.9.9.

       

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            laseranichris Christian Süßkind
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes