diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index cf22783c286..22277af52bb 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1402,6 +1402,24 @@ void QWindowsBaseWindow::setCustomMargins(const QMargins &) Q_UNIMPLEMENTED(); } +bool QWindowsBaseWindow::windowEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::ChildWindowAdded: + if (!(GetWindowLongPtr(handle(), GWL_STYLE) & WS_CLIPCHILDREN)) { + auto *childWindowEvent = static_cast(event); + qWarning() << childWindowEvent->child() << "added as child to" + << window() << "which does not have WS_CLIPCHILDREN set." + << "This will result in drawing artifacts!"; + } + break; + default: + break; + } + + return QPlatformWindow::windowEvent(event); +} + /*! \class QWindowsDesktopWindow \brief Window wrapping GetDesktopWindow not allowing any manipulation. @@ -2928,7 +2946,7 @@ bool QWindowsWindow::windowEvent(QEvent *event) break; } - return QPlatformWindow::windowEvent(event); + return QWindowsBaseWindow::windowEvent(event); } void QWindowsWindow::propagateSizeHints() diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 7805530681a..a384b4b1c7a 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -126,6 +126,8 @@ public: static QWindowsBaseWindow *baseWindowOf(const QWindow *w); static HWND handleOf(const QWindow *w); + bool windowEvent(QEvent *event) override; + protected: HWND parentHwnd() const { return GetAncestor(handle(), GA_PARENT); } bool isTopLevel_sys() const; diff --git a/tests/manual/embeddedwindows/main.cpp b/tests/manual/embeddedwindows/main.cpp index c88d1ddb99d..e34c7206eaa 100644 --- a/tests/manual/embeddedwindows/main.cpp +++ b/tests/manual/embeddedwindows/main.cpp @@ -93,15 +93,6 @@ int main(int argc, char *argv[]) NativeWindow nativeParentWindow; if (QWindow *foreignWindow = QWindow::fromWinId(nativeParentWindow)) { - -#ifdef Q_OS_WIN - // Native parent windows should have WS_CLIPCHILDREN style set - // to prevent overdrawing child area and cause flickering. - const HWND hwnd = reinterpret_cast(foreignWindow->winId()); - const LONG_PTR oldStyle = GetWindowLongPtr(hwnd, GWL_STYLE); - SetWindowLongPtr(hwnd, GWL_STYLE, oldStyle | WS_CLIPCHILDREN); -#endif - foreignWindow->setParent(&window); foreignWindow->setGeometry(50, 350, 100, 100); foreignWindow->showNormal(); diff --git a/tests/shared/nativewindow.h b/tests/shared/nativewindow.h index 163ca316347..c119280cb67 100644 --- a/tests/shared/nativewindow.h +++ b/tests/shared/nativewindow.h @@ -133,7 +133,7 @@ NativeWindow::NativeWindow() RegisterClass(&wc); return wc.lpszClassName; }(); - m_handle = CreateWindowEx(0, className, nullptr, WS_POPUP, + m_handle = CreateWindowEx(0, className, nullptr, WS_POPUP | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, GetModuleHandle(nullptr), nullptr); }