From dff58b47a786a84dc5145a73171be2c3db688fe1 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 6 Jul 2012 13:10:10 +0300 Subject: Fix embedding ActiveQt servers based on native widgets like QGLWidget Embedding a QGLWidget based server caused QGLWidget to be shown on a separate toplevel widget. This happened because it is a native widget and therefore creates a platform window before it is shown, so _q_embedded_native_parent_handle parameter we use to indicate embedded windows got set too late and consequently QGLWidget's window didn't know it was supposed to be embedded. Fixed by setting the parent in WM_SHOWWINDOW handler in these cases, and setting the window frameless, which makes platform plugin re-determine correct native flags for the window, now also taking the fact that the widget is embedded into account. Task-number: QTBUG-26438 Change-Id: Id159d864376f773775114c8f00088ce90186b65a Reviewed-by: Friedemann Kleint --- src/activeqt/control/qaxserverbase.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/activeqt/control/qaxserverbase.cpp b/src/activeqt/control/qaxserverbase.cpp index cfc47e8..1108660 100644 --- a/src/activeqt/control/qaxserverbase.cpp +++ b/src/activeqt/control/qaxserverbase.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include "qaxfactory.h" #include "qaxbindable.h" @@ -1370,8 +1371,23 @@ LRESULT QT_WIN_CALLBACK QAxServerBase::ActiveXProc(HWND hWnd, UINT uMsg, WPARAM // Set this property on window to pass the native handle to platform plugin, // so that it can create the window with proper flags instead of thinking // it is toplevel. - if (widgetWindow) + if (widgetWindow) { widgetWindow->setProperty("_q_embedded_native_parent_handle", WId(that->m_hWnd)); + + // If embedded widget is native, such as QGLWidget, it may have already created + // a window before now, probably as an undesired toplevel. In that case set the + // proper parent window and set the window frameless to position it correctly. + if (widgetWindow + && that->qt.widget->testAttribute(Qt::WA_WState_Created) + && !that->qt.widget->isVisible()) { + HWND h = static_cast(QGuiApplication::platformNativeInterface()-> + nativeResourceForWindow("handle", widgetWindow)); + if (h) + ::SetParent(h, that->m_hWnd); + Qt::WindowFlags flags = widgetWindow->windowFlags(); + widgetWindow->setWindowFlags(Qt::FramelessWindowHint); + } + } that->qt.widget->raise(); that->qt.widget->move(0, 0); } -- cgit v1.2.1