diff --git a/src/activeqt/control/qaxserverbase.cpp b/src/activeqt/control/qaxserverbase.cpp
index f2d4262444791f83cd799f5bc514961eaa05ca60..9efded27ed936b19de4806fe1c5be5131b2fc4ce 100644
--- a/src/activeqt/control/qaxserverbase.cpp
+++ b/src/activeqt/control/qaxserverbase.cpp
@@ -1400,8 +1400,13 @@ LRESULT QT_WIN_CALLBACK QAxServerBase::ActiveXProc(HWND hWnd, UINT uMsg, WPARAM
     case WM_QUERYENDSESSION:
     case WM_DESTROY:
         if (QAxServerBase *that = axServerBaseFromWindow(hWnd)) {
-            if (that->qt.widget)
+            if (that->qt.widget) {
                 that->qt.widget->hide();
+                if (QWindow *widgetWindow = that->qt.widget->windowHandle()) {
+                    if (HWND h = reinterpret_cast<HWND>(widgetWindow->winId()))
+                        ::SetParent(h, 0);
+                }
+            }
         }
         break;