diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 330c456a1d3..e1b9cfdcda1 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1357,10 +1357,12 @@ void QWindowsForeignWindow::setParent(const QPlatformWindow *newParentWindow) const HWND newParent = newParentWindow ? reinterpret_cast(newParentWindow->winId()) : HWND(nullptr); const bool isTopLevel = !newParent; const DWORD oldStyle = style(); + qCDebug(lcQpaWindow) << __FUNCTION__ << window() << "newParent=" << newParentWindow << newParent << "oldStyle=" << debugWinStyle(oldStyle); - SetParent(m_hwnd, newParent); - if (wasTopLevel != isTopLevel) { // Top level window flags need to be set/cleared manually. + + auto updateWindowFlags = [=]{ + // Top level window flags need to be set/cleared manually. DWORD newStyle = oldStyle; if (isTopLevel) { newStyle = m_topLevelStyle; @@ -1370,6 +1372,20 @@ void QWindowsForeignWindow::setParent(const QPlatformWindow *newParentWindow) newStyle |= WS_CHILD; } SetWindowLongPtr(m_hwnd, GWL_STYLE, newStyle); + }; + + if (wasTopLevel && !isTopLevel) { + // Becoming a child window requires the style + // flags to be updated before reparenting. + updateWindowFlags(); + } + + SetParent(m_hwnd, newParent); + + if (!wasTopLevel && isTopLevel) { + // Becoming a top level window requires the style + // flags to be updated after reparenting. + updateWindowFlags(); } }