summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--src/widgets/kernel/qboxlayout.cpp2
-rw-r--r--src/widgets/kernel/qlayout.cpp22
-rw-r--r--src/widgets/kernel/qlayout.h1
-rw-r--r--src/widgets/kernel/qlayoutitem.cpp30
-rw-r--r--src/widgets/kernel/qlayoutitem.h1
5 files changed, 55 insertions, 1 deletions
diff --git a/src/widgets/kernel/qboxlayout.cpp b/src/widgets/kernel/qboxlayout.cpp
index 5eaed16694..ad8f35a224 100644
--- a/src/widgets/kernel/qboxlayout.cpp
+++ b/src/widgets/kernel/qboxlayout.cpp
@@ -63,7 +63,7 @@ struct QBoxLayoutItem
}
int mhfw(int w) {
if (item->hasHeightForWidth()) {
- return item->heightForWidth(w);
+ return item->minimumHeightForWidth(w);
} else {
return item->minimumSize().height();
}
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index 39c7f7ec3f..8688e011a0 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -608,6 +608,28 @@ void QLayout::childEvent(QChildEvent *e)
\internal
Also takes contentsMargins and menu bar into account.
*/
+int QLayout::totalMinimumHeightForWidth(int w) const
+{
+ Q_D(const QLayout);
+ int side=0, top=0;
+ if (d->topLevel) {
+ QWidget *parent = parentWidget();
+ parent->ensurePolished();
+ QWidgetPrivate *wd = parent->d_func();
+ side += wd->leftmargin + wd->rightmargin;
+ top += wd->topmargin + wd->bottommargin;
+ }
+ int h = minimumHeightForWidth(w - side) + top;
+#if QT_CONFIG(menubar)
+ h += menuBarHeightForWidth(d->menubar, w);
+#endif
+ return h;
+}
+
+/*!
+ \internal
+ Also takes contentsMargins and menu bar into account.
+*/
int QLayout::totalHeightForWidth(int w) const
{
Q_D(const QLayout);
diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h
index 5fd2aa2d63..d290657945 100644
--- a/src/widgets/kernel/qlayout.h
+++ b/src/widgets/kernel/qlayout.h
@@ -127,6 +127,7 @@ public:
virtual QLayoutItem *replaceWidget(QWidget *from, QWidget *to,
Qt::FindChildOptions options = Qt::FindChildrenRecursively);
+ int totalMinimumHeightForWidth(int w) const;
int totalHeightForWidth(int w) const;
QSize totalMinimumSize() const;
QSize totalMaximumSize() const;
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
*/
diff --git a/src/widgets/kernel/qlayoutitem.h b/src/widgets/kernel/qlayoutitem.h
index a26d3949dc..ba11976f06 100644
--- a/src/widgets/kernel/qlayoutitem.h
+++ b/src/widgets/kernel/qlayoutitem.h
@@ -137,6 +137,7 @@ public:
bool hasHeightForWidth() const override;
int heightForWidth(int) const override;
+ int minimumHeightForWidth(int) const override;
QSizePolicy::ControlTypes controlTypes() const override;
protected:
QWidget *wid;