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 <richard.gustavsen@qt.io>
(cherry picked from commit 668914649c03d502935c79001baf95ac017ba061)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-05-16 13:51:11 +02:00 committed by Qt Cherry-pick Bot
parent 0f169ac80a
commit 074c812cb0

View File

@ -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);
}
/*!