From 074c812cb002867ebded6a8a251889dd35c09d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 16 May 2024 13:51:11 +0200 Subject: [PATCH] QFrame: Disable implicit inclusion of safe area margins in contents rect The QFrame::frameRect property is implemented in terms of the QWidget's contentsMargins, and when the QFrame is resized it recalculates the new frame rect by reading the contents rect and then setting the widget's content margins based on the new value. This conflicts with the implicit inclusion of safe area margins in the widget's contents rect, as those implicit margins are then persisted as user-set contents margins. If the safe area margins later change (to 0), the frame will still reflect the old safe area margins. We may find a way to untangle this for QFrame, but in the meantime let's set Qt::WA_ContentsMarginsRespectsSafeArea to false. This avoids the issue above, and also informs child widgets of the QFrame that they themselves need to potentially take the safe area margins into account. Disabling Qt::WA_ContentsMarginsRespectsSafeArea in this manner should not cause any major behavior changes, as a QFrame is typically part of a parent widget that does respect the contents margins, and so the frame will not need to apply any margins of its own once the layout settles down. Task-number: QTBUG-125345 Change-Id: I936ff5ec9056d05676560cc7659ba31105fdc224 Reviewed-by: Richard Moe Gustavsen (cherry picked from commit 668914649c03d502935c79001baf95ac017ba061) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/widgets/qframe.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/widgets/widgets/qframe.cpp b/src/widgets/widgets/qframe.cpp index db8dc20be28..1973fd24ee8 100644 --- a/src/widgets/widgets/qframe.cpp +++ b/src/widgets/widgets/qframe.cpp @@ -32,7 +32,13 @@ QFramePrivate::~QFramePrivate() inline void QFramePrivate::init() { + Q_Q(QFrame); setLayoutItemMargins(QStyle::SE_FrameLayoutItem); + + // The frameRect property is implemented in terms of the widget's + // contentsRect, which conflicts with the implicit inclusion of + // the safe area margins in the contentsRect. + q->setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, false); } /*!