Don't clear Qt::Window/ForeignWindow of QWidget if window is not top level

The logic was needed for the old QMacCocoaViewContainer, which was a
QWidget, that set Qt::ForeignWindow, and hence Qt::Window, on its
windowHandle().

The modern way of embedding a foreign window into a widget hierarchy
is via QWindow::fromWinId() and QWidget::createWindowContainer(),
which manages the foreign window as a child QWindow of the window
container's window handle, instead of replacing or modifying the
window container's own window handle.

The opposite case is a QWidget embedded into a foreign/non-widget
window hierarchy. Ideally, in this case, we should return false for
isWindow(), as the function is documented to only return true for
"if the widget is an independent window", and "a window is a widget
that isn't visually the child of any other widget and that usually
has a frame and a window title". This notion is used in many places,
including in QApplication::topLevelWidgets(), which in turn affects
the quit logic of QApplication to prevent quitting the application
as long as the child/embedded widget is visible.

Unfortunately, embedding the widget as a non-Qt::Window is not an
option at this point, as we have a lot of code paths that assume
isWindow() || parentWidget(), and these code paths break down in
flames when we end up dereferencing the (non existing) parent
widget.

As a result of removing the logic, we can now embed a QWidget into
a non-widget window hierarchy as a Qt::Window, without the removed
logic resetting the widget back to a Qt::Widget on create(), which
would send us into into the broken code paths described above.

Removing this logic should not cause issues for child widgets backed
by a native window, as those are created with Qt::Widget window flags,
not Qt::Window, so we never relied on the removed logic to sanitize
those window flags.

Task-number: QTBUG-119652
Change-Id: Id6b8e5c67bf8f83af8c2f1594806f3419303b1a1
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
bb10
Tor Arne Vestbø 2023-12-03 15:35:14 +01:00
parent 85842da95b
commit a3bec3ad37
1 changed files with 0 additions and 2 deletions

View File

@ -1313,8 +1313,6 @@ void QWidgetPrivate::create()
}
data.window_flags = win->flags();
if (!win->isTopLevel()) // In a Widget world foreign windows can only be top level
data.window_flags &= ~Qt::ForeignWindow;
#if QT_CONFIG(xcb)
if (!topData()->role.isNull()) {