From 76a0f94a6d7d85f352e3d4a00c192bfc377cc776 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 8 Oct 2019 08:05:26 +0200 Subject: [PATCH] Take widget content margin into account for menu bar size calculation The menu bar size calculation didn't take into account the margin of the layout content which makes said menu bar sticking out of the widget. This patch includes the margin to ensure the menu bar has the correct size. Fixes: QTBUG-76585 Change-Id: Ia2c163137fa2889f4028ee3b31766b2747d97b72 Reviewed-by: Christian Ehrlicher --- src/widgets/kernel/qlayout.cpp | 16 +++++++--------- src/widgets/kernel/qlayout_p.h | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 3ce81a390bc..bd06ead6f74 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -583,18 +583,18 @@ static bool removeWidgetRecursively(QLayoutItem *li, QObject *w) } -void QLayoutPrivate::doResize(const QSize &r) +void QLayoutPrivate::doResize() { Q_Q(QLayout); - int mbh = menuBarHeightForWidth(menubar, r.width()); QWidget *mw = q->parentWidget(); QRect rect = mw->testAttribute(Qt::WA_LayoutOnEntireRect) ? mw->rect() : mw->contentsRect(); + const int mbh = menuBarHeightForWidth(menubar, rect.width()); const int mbTop = rect.top(); rect.setTop(mbTop + mbh); q->setGeometry(rect); #if QT_CONFIG(menubar) if (menubar) - menubar->setGeometry(rect.left(), mbTop, r.width(), mbh); + menubar->setGeometry(rect.left(), mbTop, rect.width(), mbh); #endif } @@ -613,12 +613,10 @@ void QLayout::widgetEvent(QEvent *e) switch (e->type()) { case QEvent::Resize: - if (d->activated) { - QResizeEvent *r = (QResizeEvent *)e; - d->doResize(r->size()); - } else { + if (d->activated) + d->doResize(); + else activate(); - } break; case QEvent::ChildRemoved: { @@ -1116,7 +1114,7 @@ bool QLayout::activate() break; } - d->doResize(mw->size()); + d->doResize(); if (md->extra) { md->extra->explicitMinSize = explMin; diff --git a/src/widgets/kernel/qlayout_p.h b/src/widgets/kernel/qlayout_p.h index 8e1d773355b..2b19af48be4 100644 --- a/src/widgets/kernel/qlayout_p.h +++ b/src/widgets/kernel/qlayout_p.h @@ -73,7 +73,7 @@ class Q_WIDGETS_EXPORT QLayoutPrivate : public QObjectPrivate QLayoutPrivate(); void getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const; - void doResize(const QSize &); + void doResize(); void reparentChildWidgets(QWidget *mw); bool checkWidget(QWidget *widget) const; bool checkLayout(QLayout *otherLayout) const;