Improve handling of minimumHeightForWidth()
This also aligns the implementation with QWidgetItem::heightForWidth() Fixes: QTBUG-92599 Change-Id: I0de68c61ec37a16a8c338575d07ff9e8168a0b98 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io> (cherry picked from commit 4d4eb11fe340bf0b3a1ce0caae62d9319bf941cf) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a22acb8ba5
commit
d9697f9f5d
@ -63,7 +63,7 @@ struct QBoxLayoutItem
|
|||||||
}
|
}
|
||||||
int mhfw(int w) {
|
int mhfw(int w) {
|
||||||
if (item->hasHeightForWidth()) {
|
if (item->hasHeightForWidth()) {
|
||||||
return item->heightForWidth(w);
|
return item->minimumHeightForWidth(w);
|
||||||
} else {
|
} else {
|
||||||
return item->minimumSize().height();
|
return item->minimumSize().height();
|
||||||
}
|
}
|
||||||
|
@ -604,6 +604,28 @@ void QLayout::childEvent(QChildEvent *e)
|
|||||||
removeItem(childLayout);
|
removeItem(childLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\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
|
\internal
|
||||||
Also takes contentsMargins and menu bar into account.
|
Also takes contentsMargins and menu bar into account.
|
||||||
|
@ -127,6 +127,7 @@ public:
|
|||||||
virtual QLayoutItem *replaceWidget(QWidget *from, QWidget *to,
|
virtual QLayoutItem *replaceWidget(QWidget *from, QWidget *to,
|
||||||
Qt::FindChildOptions options = Qt::FindChildrenRecursively);
|
Qt::FindChildOptions options = Qt::FindChildrenRecursively);
|
||||||
|
|
||||||
|
int totalMinimumHeightForWidth(int w) const;
|
||||||
int totalHeightForWidth(int w) const;
|
int totalHeightForWidth(int w) const;
|
||||||
QSize totalMinimumSize() const;
|
QSize totalMinimumSize() const;
|
||||||
QSize totalMaximumSize() const;
|
QSize totalMaximumSize() const;
|
||||||
|
@ -575,6 +575,36 @@ int QWidgetItem::heightForWidth(int w) const
|
|||||||
return hfw;
|
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
|
\reimp
|
||||||
*/
|
*/
|
||||||
|
@ -137,6 +137,7 @@ public:
|
|||||||
|
|
||||||
bool hasHeightForWidth() const override;
|
bool hasHeightForWidth() const override;
|
||||||
int heightForWidth(int) const override;
|
int heightForWidth(int) const override;
|
||||||
|
int minimumHeightForWidth(int) const override;
|
||||||
QSizePolicy::ControlTypes controlTypes() const override;
|
QSizePolicy::ControlTypes controlTypes() const override;
|
||||||
protected:
|
protected:
|
||||||
QWidget *wid;
|
QWidget *wid;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user