summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 7d8539bcdbc..32ac298ac8e 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -10943,10 +10943,19 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
QWidget *parentWithWindow = closestParentWidgetWithWindowHandle();
// But if the widget is about to be destroyed we must skip the
// widget itself, and only reparent children.
- if (destroyWindow)
+ if (destroyWindow) {
reparentWidgetWindowChildren(parentWithWindow);
- else
+ } else {
+ // During reparentWidgetWindows() we need to know whether the reparented
+ // QWindow should be a top level (with a transient parent) or not. This
+ // widget has not updated its window flags yet, so we can't ask the widget
+ // directly at that point. Nor can we use the QWindow flags, as unlike QWidgets
+ // the QWindow flags always reflect Qt::Window, even for child windows. And
+ // we can't use QWindow::isTopLevel() either, as that depends on the parent,
+ // which we are in the process of updating. So we propagate the
+ // new flags of the reparented window here.
reparentWidgetWindows(parentWithWindow, f);
+ }
}
bool explicitlyHidden = isExplicitlyHidden();
@@ -11003,13 +11012,6 @@ void QWidgetPrivate::reparentWidgetWindows(QWidget *parentWithWindow, Qt::Window
if (QWindow *window = windowHandle()) {
// Reparent this QWindow, and all QWindow children will follow
if (parentWithWindow) {
- // The reparented widget has not updated its window flags yet,
- // so we can't ask the widget directly. And we can't use the
- // QWindow flags, as unlike QWidgets the QWindow flags always
- // reflect Qt::Window, even for child windows. And we can't use
- // QWindow::isTopLevel() either, as that depends on the parent,
- // which we are in the process of updating. So we propagate the
- // new flags of the reparented window from setParent_sys().
if (windowFlags & Qt::Window) {
// Top level windows can only have transient parents,
// and the transient parent must be another top level.
@@ -11040,7 +11042,9 @@ void QWidgetPrivate::reparentWidgetWindowChildren(QWidget *parentWithWindow)
for (auto *child : std::as_const(children)) {
if (auto *childWidget = qobject_cast<QWidget*>(child)) {
auto *childPrivate = QWidgetPrivate::get(childWidget);
- childPrivate->reparentWidgetWindows(parentWithWindow);
+ // Child widgets with QWindows should always continue to be child
+ // windows, so we pass on the child's current window flags here.
+ childPrivate->reparentWidgetWindows(parentWithWindow, childWidget->windowFlags());
}
}
}