Widgets: Don't assume layout handles safe area margins if widget opts out
As an optimization when calculating the safe area margins for child widgets we look at the parent hierarchy, and if we find a widget that is in a layout, and that layout respects the widget's contents rect, we assume the safe area margins are accounted for already. But this relies on the widget the layout is operating on to not opt out of the safe area margins affecting the contents rect. If it does, the layout can't help us, and we need to fall back to computing the child widget's safe area margins. Task-number: QTBUG-125345 Change-Id: I2e2f7d292d2b2c3ecd2e2e95316c4d72b92db5d6 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
parent
68ceb847d6
commit
35cdd8abf6
@ -7694,11 +7694,15 @@ QMargins QWidgetPrivate::safeAreaMargins() const
|
||||
return QMargins();
|
||||
|
||||
// Or, if one of our ancestors are in a layout that does not have WA_LayoutOnEntireRect
|
||||
// set, then we know that the layout has already taken care of placing us inside the
|
||||
// safe area, by taking the contents rect of its parent widget into account.
|
||||
// set, and the widget respects the safe area, then we know that the layout has already
|
||||
// taken care of placing us inside the safe area, by taking the contents rect of its
|
||||
// parent widget into account.
|
||||
const QWidget *assumedSafeWidget = nullptr;
|
||||
for (const QWidget *w = q; w != nativeWidget; w = w->parentWidget()) {
|
||||
QWidget *parentWidget = w->parentWidget();
|
||||
if (!parentWidget->testAttribute(Qt::WA_ContentsMarginsRespectsSafeArea))
|
||||
continue; // Layout can't help us
|
||||
|
||||
if (parentWidget->testAttribute(Qt::WA_LayoutOnEntireRect))
|
||||
continue; // Layout not going to help us
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user