Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.12.12, 6.2.3
-
None
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.