From d0f4ce324890197683869eafda0f3938ae619b8d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 26 Mar 2020 07:09:01 +0100 Subject: [PATCH] Added support to adhere the minimumSizeHint() of the content widget of a dock widget --- src/DockWidget.cpp | 17 ++++++++++++++++- src/DockWidget.h | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 48fb857..9de729d 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -82,6 +82,7 @@ struct DockWidgetPrivate QSize ToolBarIconSizeFloating = QSize(24, 24); bool IsFloatingTopLevel = false; QList TitleBarActions; + CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget; /** * Private data constructor @@ -424,6 +425,13 @@ void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode) } +//============================================================================ +void CDockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode Mode) +{ + d->MinimumSizeHintMode = Mode; +} + + //============================================================================ void CDockWidget::toggleView(bool Open) { @@ -753,7 +761,14 @@ void CDockWidget::setClosedState(bool Closed) //============================================================================ QSize CDockWidget::minimumSizeHint() const { - return QSize(60, 40); + if (d->MinimumSizeHintMode == CDockWidget::MinimumSizeHintFromDockWidget || !d->Widget) + { + return QSize(60, 40); + } + else + { + return d->Widget->minimumSizeHint(); + } } diff --git a/src/DockWidget.h b/src/DockWidget.h index 1cb6f63..de3e8a2 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -189,6 +189,23 @@ public: ForceNoScrollArea }; + + /** + * The mode of the minimumSizeHint() that is returned by the DockWidget + * minimumSizeHint() function. + * To ensure, that a dock widget does not block resizing, the dock widget + * reimplements minimumSizeHint() function to return a very small minimum + * size hint. If you would like to adhere the minimumSizeHint() from the + * content widget, the set the minimumSizeHintMode() to + * MinimumSizeHintFromContent. + */ + enum eMinimumSizeHintMode + { + MinimumSizeHintFromDockWidget, + MinimumSizeHintFromContent + }; + + /** * This mode configures the behavior of the toggle view action. * If the mode if ActionModeToggle, then the toggle view action is @@ -334,6 +351,13 @@ public: */ void setToggleViewActionMode(eToggleViewActionMode Mode); + /** + * Configures the minimum size hint that is returned by the + * minimumSizeHint() function. + * \see eMinimumSizeHintMode for a detailed description + */ + void setMinimumSizeHintMode(eMinimumSizeHintMode Mode); + /** * Sets the dock widget icon that is shown in tabs and in toggle view * actions