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

QDockWidgets of maximized windows are not restored to the correct size when calling QWidget::restoreGeometry() , QMainWindow::restoreState() in a sequence

    XMLWordPrintable

Details

    • cbfb6bda1d1ce3e169db6a0deb9bd901076653e4

    Description

      The geometry is not restored correctly when running the example below and following these steps:

      1. Build and run the app,
      2. Maximize the mainwindow and put dockwidget1 in the left dockarea and dockwidget2 in the bottom dockarea.
      3. Close the application.
      4. Run the application again. The geometry and state are correct.
      5. Resize the left dock and bottom dock bigger, so that the central widget is displayed very small in the top right corner.
      6. Close the app
      8. Re-run the app - the geometry and state from point 5 are not restored, instead the geometry and state from point 2 are shown.

      #include <QtGui>
      #if QT_VERSION >= 0x50000
      #include <QtWidgets>
      #endif
      
      class MainWindow : public QMainWindow
      {
      public:
      	MainWindow()
      	{
      		setCentralWidget(new QTextEdit(this));
      		QDockWidget *dock1 = new QDockWidget(this);
      		dock1->setObjectName("First dock");
      		dock1->setWidget(new QLabel("Label 1", dock1));
      		QDockWidget *dock2 = new QDockWidget(this);
      		dock2->setObjectName("Second dock");
      		dock2->setWidget(new QLabel("Label 2", dock2));
      		addDockWidget(Qt::TopDockWidgetArea, dock1);
      		addDockWidget(Qt::TopDockWidgetArea, dock2);
      		readSettings();
      	}
      	void readSettings() {
      		QSettings settings("SomeTest", "SaveRestore Example");
      		restoreGeometry(settings.value("geometry").toByteArray());
      		restoreState(settings.value("windowState").toByteArray());
      	}
      
      	void writeSettings()
      	{
      		QSettings settings("SomeTest", "SaveRestore Example");
      		settings.setValue("geometry", saveGeometry());
      		settings.setValue("windowState", saveState());
      	}
      
      	void closeEvent(QCloseEvent *event)
      	{
      		QMainWindow::closeEvent(event);
      		writeSettings();
      	}
      };
      
      int main(int argc, char** argv)
      {
      	QApplication app(argc, argv);
      	MainWindow window;
      	window.show();
      	return app.exec();
      }

      with qtbug16252.zip:

      • Run app, maximize
      • Enlarge left dock widget until it covers approx 2/3 of screen width
      • Quit
      • Relaunch: Note dock widget width is not restored

      Attachments

        Issue Links

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

          Activity

            People

              anwojcie Anna Wojciechowska
              naevdal Sigrid Fjell Nævdal (Inactive)
              Votes:
              38 Vote for this issue
              Watchers:
              48 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There is 1 open Gerrit change