Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Restore/Preserve QDockWidget's geometry/size
Qt 6.11 is out! See what's new in the release blog

Restore/Preserve QDockWidget's geometry/size

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    soma_yarram
    wrote on last edited by
    #1

    My Qt application has a QMainWindow whose central widget can be switched/changed with the click of a button.

    And each central widget has set of its own QDockWidget's.

    On switching/changing central widget, corresponding QDockWidget's are shown and rest are hidden.

    I have a problem that: the sizes of newly shown QDockWidget's are changed (by Qt internally), losing the sizes set by the user.

    FYI: I tried QDockWidget::restoreGeometry(...) after showing new QDockWidget's, but it did not work.

    Any help is much appreciated.

    jsulmJ 1 Reply Last reply
    0
    • S soma_yarram

      My Qt application has a QMainWindow whose central widget can be switched/changed with the click of a button.

      And each central widget has set of its own QDockWidget's.

      On switching/changing central widget, corresponding QDockWidget's are shown and rest are hidden.

      I have a problem that: the sizes of newly shown QDockWidget's are changed (by Qt internally), losing the sizes set by the user.

      FYI: I tried QDockWidget::restoreGeometry(...) after showing new QDockWidget's, but it did not work.

      Any help is much appreciated.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @soma_yarram I would use https://doc.qt.io/qt-5/qstackedwidget.html instead of changing central widget.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        soma_yarram
        wrote on last edited by
        #3

        @jsulm : Yes, I do use QStackedWidget to change my main (central) widget instead of calling QMainWindow::setCentralWidget(...).

        When I call QStackedWidget::setCurrentWidget(...), I show new QDockWidget's (by calling QDockWidget::setVisible(true)) and hide previously visible QDockWidget's (by calling QDockWidget::setVisible(false)).
        But my problem is that: the sizes of newly shown QDockWidget's are changed (by Qt internally), losing the sizes set by the user.

        FYI: I call QStackedWidget::addWidget(...) and QMainWindow::addDockWidget(...) during the application startup.

        jsulmJ 1 Reply Last reply
        0
        • S soma_yarram

          @jsulm : Yes, I do use QStackedWidget to change my main (central) widget instead of calling QMainWindow::setCentralWidget(...).

          When I call QStackedWidget::setCurrentWidget(...), I show new QDockWidget's (by calling QDockWidget::setVisible(true)) and hide previously visible QDockWidget's (by calling QDockWidget::setVisible(false)).
          But my problem is that: the sizes of newly shown QDockWidget's are changed (by Qt internally), losing the sizes set by the user.

          FYI: I call QStackedWidget::addWidget(...) and QMainWindow::addDockWidget(...) during the application startup.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @soma_yarram said in Restore/Preserve QDockWidget's geometry/size:

          I show new QDockWidget's (by calling QDockWidget::setVisible(true))

          Why? It should be enough to activate the correct widget using https://doc.qt.io/qt-5/qstackedwidget.html#currentIndex-prop or https://doc.qt.io/qt-5/qstackedwidget.html#setCurrentWidget

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S Offline
            S Offline
            soma_yarram
            wrote on last edited by
            #5

            @jsulm : Yes, I change my main (central) widget by calling QStackedWidget::setCurrentWidget(...).

            Actually the application has following structure:
            Step 1: I created QWidget_1 and QWidget_2, and added to QStackWidget (which is the central widget of my QMainWindow).

            Step2: I created QDockWidget_1_1, QDockWidget_1_2, QDockWidget_2_1 and QDockWidget_2_2, and added to QMainWindow (using QMainWindow::addDockWidget(Qt::RightDockWidgetArea, ...)).

            Step 3: I (or user) call QStackedWidget::setCurrentWidget(QWidget_1), which internally calls
            QDockWidget_1_1::setVisible(true),
            QDockWidget_1_2::setVisible(true),
            QDockWidget_2_1::setVisible(false),
            QDockWidget_2_2::setVisible(false).
            This hides QDockWidget_2_1 and QDockWidget_2_2, and shows QDockWidget_1_1 and QDockWidget_1_2.

            Step 4: User adjusts the sizes of QDockWidget_1_1 and QDockWidget_1_2 (using the splitter handle added by QMainWindow).

            Step 5: I (or user) call QStackedWidget::setCurrentWidget(QWidget_2), which internally calls
            QDockWidget_1_1::setVisible(false),
            QDockWidget_1_2::setVisible(false),
            QDockWidget_2_1::setVisible(true),
            QDockWidget_2_2::setVisible(true).
            This hides QDockWidget_1_1 and QDockWidget_1_2, and shows QDockWidget_2_1 and QDockWidget_2_2.

            Step 6: User adjusts the sizes of QDockWidget_2_1 and QDockWidget_2_2 (using the splitter handle added by QMainWindow).

            Step 7: Again, I (or user) call QStackedWidget::setCurrentWidget(QWidget_1), which internally calls
            QDockWidget_1_1::setVisible(true),
            QDockWidget_1_2::setVisible(true),
            QDockWidget_2_1::setVisible(false),
            QDockWidget_2_2::setVisible(false).
            This hides QDockWidget_2_1 and QDockWidget_2_2, and shows QDockWidget_1_1 and QDockWidget_1_2.
            But this time, the sizes of QDockWidget_1_1 and QDockWidget_1_2 are different to the ones that are set by the user in Step 4.

            My question is: how can I restore the sizes of QDockWidget_1_1 and QDockWidget_1_2 that are set by the user in Step 4?

            Hope you understand. Thanks in advance.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              @soma_yarram said in Restore/Preserve QDockWidget's geometry/size:

              FYI: I tried QDockWidget::restoreGeometry(...) after showing new QDockWidget's, but it did not work.

              Did you gave an objectName (as explained in the QMainWindow::saveState ) to all your QDockWidget to be restored ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved