diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-03-19 17:31:56 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-03-26 04:10:07 +0000 |
commit | d0f016ebfb86fcebcf72c37c489260a0d02147e7 (patch) | |
tree | 47b8e8d321a2a9ea5e1bb3b169d23bf8de8efeaf /src/widgets | |
parent | 4054759aecd06313a775c8c71748ec52ca7dc27d (diff) |
Ensure that layouts don't move widgets outside of their parent
When using a style that wants to draw into the layout's margin (like
macOS style does with group box titles), parts of the widgets would be
clipped by the parent if the available margin is smaller than necessary.
This moves the x/y coordinates to at least 0/0, and adjusts width and
height accordingly.
[ChangeLog][QtWidgets][QLayout] Prevent clipping of group box titles
on macOS (and similar styles that draw into layout margins)
Change-Id: I32148a92858c13fb2325da4d0a2a58996e0e8930
Fixes: QTBUG-67608
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qlayoutitem.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp index 9e6d1c5eac..0aab0bb06d 100644 --- a/src/widgets/kernel/qlayoutitem.cpp +++ b/src/widgets/kernel/qlayoutitem.cpp @@ -502,6 +502,17 @@ void QWidgetItem::setGeometry(const QRect &rect) else if (!(align & Qt::AlignTop)) y = y + (r.height() - s.height()) / 2; + // Make sure we don't move outside of the parent, e.g when styles demand + // surplus space that exceeds the available margins (f.ex macOS with QGroupBox) + if (x < 0) { + s.rwidth() += x; + x = 0; + } + if (y < 0) { + s.rheight() += y; + y = 0; + } + wid->setGeometry(x, y, s.width(), s.height()); } |