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

Tabified QDockWidget geometry not saving

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.2
    • Widgets: Main Window
    • None
    • Linux/Wayland, Windows

    Description

      We're creating the main window with multiple dock widgets. Our current goal is to save the whole layout on exit. Everything works fine until we try to tabify some dock widgets using the tabifyDockWidget() method. And now the tabified widgets don't save their geometry for some reason.

      Here is the minimal reproducible example. You can check the described behavior by (un)commenting the tabifyDockWidget() line, resizing the dock widgets, and restarting the application. Don't forget to remove the saved settings file between the tests in order to reset the layout to its initial state.

      #include "mainwindow.h"
      #include <QDockWidget>
      #include <QLabel>
      #include <QSettings>
      
      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
      {
          resize(800, 320);
      
          auto centralWidget = new QLabel("Central Widget", this);
          centralWidget->setAlignment(Qt::AlignCenter);
          centralWidget->setStyleSheet("border: 2px solid black");
          setCentralWidget(centralWidget);
      
          auto dockLeft1 = new QDockWidget(this);
          auto dockLeft2 = new QDockWidget(this);
          auto dockRight = new QDockWidget(this);
      
          dockLeft1->setObjectName("dockLeft1");
          dockLeft2->setObjectName("dockLeft2");
          dockRight->setObjectName("dockRight");
      
          dockLeft1->setWindowTitle(tr("Left Dock 1"));
          dockLeft2->setWindowTitle(tr("Left Dock 2"));
          dockRight->setWindowTitle(tr("Right Dock"));
      
          addDockWidget(Qt::LeftDockWidgetArea, dockLeft1);
          addDockWidget(Qt::LeftDockWidgetArea, dockLeft2);
          addDockWidget(Qt::RightDockWidgetArea, dockRight);
      
          tabifyDockWidget(dockLeft1, dockLeft2);
      
          QSettings settings("foo", "bar");
          restoreGeometry(settings.value("geometry").toByteArray());
          restoreState(settings.value("state").toByteArray());
      }
      
      void MainWindow::closeEvent(QCloseEvent *event)
      {
          QSettings settings("foo", "bar");
          settings.setValue("geometry", saveGeometry());
          settings.setValue("state", saveState());
      
          QMainWindow::closeEvent(event);
      } 

      Behavior without tabifyDockWidget()

      • Resize left and right dock widgets.
      • Close and reopen the application.
      • The layout settings restore just fine.

      Behavior with tabifyDockWidget()

      • Resize left and right dock widgets.
      • Close and reopen the application.
      • The restored geometry is wrong for the left (tabified) dock.

      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
            kefir500 Alexander Gorishnyak
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes