From 51300566ffe2ece2455e1d0479a556c5dbb3bb8e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 23 Sep 2021 17:16:13 +0200 Subject: Fix closing and showing a window with a native child Closing a window with a native child results in the native child's QWidgetWindow being closed. That explicitly calls setVisible(false) on the child, which will still have the ExplicitShowHide attribute set from the initial (explicit) show. Even though we then reset the ExplicitShowHide, the WState_Hidden attribute will still be set, so Qt considers the window to have been hidden, and not show it again when the parent becomes visible. Add a test case. Fixes: QTBUG-96286 Fixes: QTBUG-79012 Fixes: QTBUG-71519 Change-Id: I482e6d5236c959d82ce66798176b259a3176972c Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff --- src/widgets/kernel/qwidgetwindow.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/widgets/kernel/qwidgetwindow.cpp') diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 69c76112f6..e3563dc301 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -78,10 +78,13 @@ public: // explicitly and not because the parent window in this case made it hidden. // In which case do not automatically show the widget when the parent // window is shown. + const bool wasExplicitShowHide = widget->testAttribute(Qt::WA_WState_ExplicitShowHide); const bool wasHidden = widget->testAttribute(Qt::WA_WState_Hidden); QWidgetPrivate::get(widget)->setVisible(visible); - if (!wasHidden) - widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false); + if (wasExplicitShowHide) { + widget->setAttribute(Qt::WA_WState_ExplicitShowHide, wasExplicitShowHide); + widget->setAttribute(Qt::WA_WState_Hidden, wasHidden); + } } else { QWindowPrivate::setVisible(visible); } -- cgit v1.2.3