From 2df22bdb64c2953d3eb1ca3c51a59601770157af Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 11 May 2020 22:05:43 +0800 Subject: [PATCH] Fix QWindow disappear bug of Qt Quick. Restoring window styles to default will break Qt Quick applications. The QWindow will disappear once we do it. Qt Widgets applications are not affected. Don't know why currently. Disable it by default because it's not something we must do. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- winnativeeventfilter.cpp | 34 ++++++++++++++++++++-------------- winnativeeventfilter.h | 3 ++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/winnativeeventfilter.cpp b/winnativeeventfilter.cpp index 5a624c0..23a4b6e 100644 --- a/winnativeeventfilter.cpp +++ b/winnativeeventfilter.cpp @@ -932,20 +932,26 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, if (!data->initialized) { // Avoid initializing a same window twice. data->initialized = TRUE; - // Restore default window style. - // WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | - // WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX - // Apply the WS_OVERLAPPEDWINDOW window style to restore the window - // to a normal native Win32 window. - // Don't apply the Qt::FramelessWindowHint flag, it will add the - // WS_POPUP window style to the window, which will turn the window - // into a popup window, losing all the functions a normal window - // should have. - // WS_CLIPCHILDREN | WS_CLIPSIBLINGS: work-around strange bugs. - m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, - WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | - WS_CLIPSIBLINGS); - if (!data->windowData.notLayeredWindow) { + // Don't restore the window styles to default when you are + // developing Qt Quick applications because the QWindow + // will disappear once you do it. However, Qt Widgets applications + // are not affected. Don't know why currently. + if (data->windowData.restoreDefaultWindowStyles) { + // Restore default window style. + // WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU + // | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX + // Apply the WS_OVERLAPPEDWINDOW window style to restore the + // window to a normal native Win32 window. + // Don't apply the Qt::FramelessWindowHint flag, it will add + // the WS_POPUP window style to the window, which will turn + // the window into a popup window, losing all the functions + // a normal window should have. + // WS_CLIPCHILDREN | WS_CLIPSIBLINGS: work-around strange bugs. + m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | + WS_CLIPSIBLINGS); + } + if (!data->windowData.doNotEnableLayeredWindow) { // Turn our window into a layered window to get better // performance and hopefully, to get rid of some strange bugs at // the same time. But this will break the Arcylic effect diff --git a/winnativeeventfilter.h b/winnativeeventfilter.h index c6fe692..ec2ea00 100644 --- a/winnativeeventfilter.h +++ b/winnativeeventfilter.h @@ -54,7 +54,8 @@ class WinNativeEventFilter : public QAbstractNativeEventFilter { public: using WINDOWDATA = struct _WINDOWDATA { BOOL fixedSize = FALSE, mouseTransparent = FALSE, - notLayeredWindow = FALSE; + restoreDefaultWindowStyles = FALSE, + doNotEnableLayeredWindow = FALSE; int borderWidth = -1, borderHeight = -1, titleBarHeight = -1; QVector ignoreAreas = {}, draggableAreas = {}; QVector> ignoreObjects = {}, draggableObjects = {};