summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qlayoutitem.cpp
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2021-05-07 11:38:24 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2021-05-10 08:24:13 +0000
commit4d4eb11fe340bf0b3a1ce0caae62d9319bf941cf (patch)
treef2c13d3ae331063ae79e5a2777f5ae2a441dfaf6 /src/widgets/kernel/qlayoutitem.cpp
parent036c13a0f48ea964da36c6ac01b379d9aa52fdc1 (diff)
Improve handling of minimumHeightForWidth()
This also aligns the implementation with QWidgetItem::heightForWidth() Fixes: QTBUG-92599 Pick-to: 5.15 6.1 Change-Id: I0de68c61ec37a16a8c338575d07ff9e8168a0b98 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/widgets/kernel/qlayoutitem.cpp')
-rw-r--r--src/widgets/kernel/qlayoutitem.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp
index 8a0cdc2a64..b241821c82 100644
--- a/src/widgets/kernel/qlayoutitem.cpp
+++ b/src/widgets/kernel/qlayoutitem.cpp
@@ -575,6 +575,36 @@ int QWidgetItem::heightForWidth(int w) const
return hfw;
}
+int QWidgetItem::minimumHeightForWidth(int w) const
+{
+ if (isEmpty())
+ return -1;
+
+ w = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
+ ? fromLayoutItemSize(wid->d_func(), QSize(w, 0)).width()
+ : w;
+
+ int hfw;
+ if (wid->layout())
+ hfw = wid->layout()->totalMinimumHeightForWidth(w);
+ else
+ hfw = wid->heightForWidth(w); // QWidget doesn't have minimumHeightForWidth()
+
+ if (hfw > wid->maximumHeight())
+ hfw = wid->maximumHeight();
+ if (hfw < wid->minimumHeight())
+ hfw = wid->minimumHeight();
+
+ hfw = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
+ ? toLayoutItemSize(wid->d_func(), QSize(0, hfw)).height()
+ : hfw;
+
+ if (hfw < 0)
+ hfw = 0;
+ return hfw;
+
+}
+
/*!
\reimp
*/