From d0f016ebfb86fcebcf72c37c489260a0d02147e7 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 19 Mar 2019 17:31:56 +0100 Subject: 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 --- src/widgets/kernel/qlayoutitem.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/widgets') 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()); } -- cgit v1.2.3