diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qboxlayout.cpp | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qlayout.cpp | 22 | ||||
-rw-r--r-- | src/widgets/kernel/qlayout.h | 1 | ||||
-rw-r--r-- | src/widgets/kernel/qlayoutitem.cpp | 30 | ||||
-rw-r--r-- | src/widgets/kernel/qlayoutitem.h | 1 |
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; |