Restore/Preserve QDockWidget's geometry/size
-
My Qt application has a
QMainWindowwhose 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 newQDockWidget's, but it did not work.Any help is much appreciated.
-
My Qt application has a
QMainWindowwhose 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 newQDockWidget's, but it did not work.Any help is much appreciated.
@soma_yarram I would use https://doc.qt.io/qt-5/qstackedwidget.html instead of changing central widget.
-
@jsulm : Yes, I do use
QStackedWidgetto change my main (central) widget instead of callingQMainWindow::setCentralWidget(...).When I call
QStackedWidget::setCurrentWidget(...), I show newQDockWidget's (by callingQDockWidget::setVisible(true)) and hide previously visibleQDockWidget's (by callingQDockWidget::setVisible(false)).
But my problem is that: the sizes of newly shownQDockWidget's are changed (by Qt internally), losing the sizes set by the user.FYI: I call
QStackedWidget::addWidget(...)andQMainWindow::addDockWidget(...)during the application startup. -
@jsulm : Yes, I do use
QStackedWidgetto change my main (central) widget instead of callingQMainWindow::setCentralWidget(...).When I call
QStackedWidget::setCurrentWidget(...), I show newQDockWidget's (by callingQDockWidget::setVisible(true)) and hide previously visibleQDockWidget's (by callingQDockWidget::setVisible(false)).
But my problem is that: the sizes of newly shownQDockWidget's are changed (by Qt internally), losing the sizes set by the user.FYI: I call
QStackedWidget::addWidget(...)andQMainWindow::addDockWidget(...)during the application startup.@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
-
@jsulm : Yes, I change my main (central) widget by calling
QStackedWidget::setCurrentWidget(...).Actually the application has following structure:
Step 1: I createdQWidget_1andQWidget_2, and added toQStackWidget(which is the central widget of myQMainWindow).Step2: I created
QDockWidget_1_1,QDockWidget_1_2,QDockWidget_2_1andQDockWidget_2_2, and added toQMainWindow(usingQMainWindow::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 hidesQDockWidget_2_1andQDockWidget_2_2, and showsQDockWidget_1_1andQDockWidget_1_2.Step 4: User adjusts the sizes of
QDockWidget_1_1andQDockWidget_1_2(using the splitter handle added byQMainWindow).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 hidesQDockWidget_1_1andQDockWidget_1_2, and showsQDockWidget_2_1andQDockWidget_2_2.Step 6: User adjusts the sizes of
QDockWidget_2_1andQDockWidget_2_2(using the splitter handle added byQMainWindow).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 hidesQDockWidget_2_1andQDockWidget_2_2, and showsQDockWidget_1_1andQDockWidget_1_2.
But this time, the sizes ofQDockWidget_1_1andQDockWidget_1_2are 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_1andQDockWidget_1_2that are set by the user in Step 4?Hope you understand. Thanks in advance.
-
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 ?