qt6-bb10/tests/auto/widgets
Tor Arne Vestbø c956eb8edd Reparent QWindow children when reparenting QWidget
When a QWidget was reparented, we would take care to reparent its
backing QWidgetWindow as well, into the nearest QWindow of the
new QWidget parent.

However we would only do this for the reparented widget itself,
and not any of its child widgets. In the case where the widget
has native children with their own QWindows, the widget itself
may not (yet) be native, e.g. if it hasn't been shown yet, or
if the user has set Qt::WA_DontCreateNativeAncestors.

In these scenarios, we would be left with dangling QWindows,
still hanging off their original QWindow parents, which
would eventually lead to crashes.

We now reparent both the QWindow of the reparented widget (as
long as it's not about to be destroyed), and any QQWindow
children we can reach. For each child hierarchy we can stop
once we reach a QWindow, as the QWindow children of that
window will follow along once we reparent the QWindow.

QWindowContainer widgets don't usually have their own
windowHandle(), but still manage a QWindow inside their
parent widget hierarchy. These will not be reparented
during QWidgetPrivate::setParent_sys(), but instead
do their own reparenting later in QWidget::setParent
via QWindowContainer::parentWasChanged(). The only
exception to this is when the top level is about to
be destroyed, in which case we let the window container
know during QWidgetPrivate::setParent_sys().

Finally, although there should not be any leftover
QWindows in the reparented widget once we have done
the QWidgetWindow and QWindowContainer reparenting,
we still do a pass over any remaining QWindows and
reparent those too, since the original code included
this as a possibility.

We could make further improvements in this areas, such
as moving the QWindowContainer::parentWasChanged() call,
but the goal was to keep this change as minimal as possible
so we can back-port it.

Fixes: QTBUG-122747
Pick-to: 6.7.0 6.7 6.6 6.5
Change-Id: I4d1217fce4c3c48cf5f7bfbe9d561ab408ceebb2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-03-14 13:50:36 +00:00
..
dialogs QMessageBox: Respect explicit accept/reject after closing dialog 2024-03-14 14:50:36 +01:00
effects Change license for tests files 2024-02-04 09:56:42 +01:00
graphicsview Remove extra semi-colons 2024-02-06 20:17:18 +09:00
itemviews tests: blacklist tst_QIV::focusNextOnHide() on Wayland 2024-03-14 14:50:35 +01:00
kernel Reparent QWindow children when reparenting QWidget 2024-03-14 13:50:36 +00:00
styles Change license for tests files 2024-02-04 09:56:42 +01:00
util Change license for tests files 2024-02-04 09:56:42 +01:00
widgets QDialogButtonBox: Don't set focus in a dialog with StrongFocus children 2024-03-07 23:00:33 +00:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00