Skip to content

Commit

Permalink
Take widget content margin into account for menu bar size calculation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sgaist committed Nov 15, 2019
1 parent 01ec115 commit 76a0f94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/widgets/kernel/qlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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:
{
Expand Down Expand Up @@ -1116,7 +1114,7 @@ bool QLayout::activate()
break;
}

d->doResize(mw->size());
d->doResize();

if (md->extra) {
md->extra->explicitMinSize = explMin;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/kernel/qlayout_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 76a0f94

Please sign in to comment.