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>
This commit is contained in:
Yuhang Zhao 2020-05-11 22:05:43 +08:00
parent 48ff3280b1
commit 2df22bdb64
2 changed files with 22 additions and 15 deletions

View File

@ -932,20 +932,26 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
if (!data->initialized) { if (!data->initialized) {
// Avoid initializing a same window twice. // Avoid initializing a same window twice.
data->initialized = TRUE; data->initialized = TRUE;
// 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. // Restore default window style.
// WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | // WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
// WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX // | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
// Apply the WS_OVERLAPPEDWINDOW window style to restore the window // Apply the WS_OVERLAPPEDWINDOW window style to restore the
// to a normal native Win32 window. // window to a normal native Win32 window.
// Don't apply the Qt::FramelessWindowHint flag, it will add the // Don't apply the Qt::FramelessWindowHint flag, it will add
// WS_POPUP window style to the window, which will turn the window // the WS_POPUP window style to the window, which will turn
// into a popup window, losing all the functions a normal window // the window into a popup window, losing all the functions
// should have. // a normal window should have.
// WS_CLIPCHILDREN | WS_CLIPSIBLINGS: work-around strange bugs. // WS_CLIPCHILDREN | WS_CLIPSIBLINGS: work-around strange bugs.
m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE, m_lpSetWindowLongPtrW(msg->hwnd, GWL_STYLE,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS); WS_CLIPSIBLINGS);
if (!data->windowData.notLayeredWindow) { }
if (!data->windowData.doNotEnableLayeredWindow) {
// Turn our window into a layered window to get better // Turn our window into a layered window to get better
// performance and hopefully, to get rid of some strange bugs at // performance and hopefully, to get rid of some strange bugs at
// the same time. But this will break the Arcylic effect // the same time. But this will break the Arcylic effect

View File

@ -54,7 +54,8 @@ class WinNativeEventFilter : public QAbstractNativeEventFilter {
public: public:
using WINDOWDATA = struct _WINDOWDATA { using WINDOWDATA = struct _WINDOWDATA {
BOOL fixedSize = FALSE, mouseTransparent = FALSE, BOOL fixedSize = FALSE, mouseTransparent = FALSE,
notLayeredWindow = FALSE; restoreDefaultWindowStyles = FALSE,
doNotEnableLayeredWindow = FALSE;
int borderWidth = -1, borderHeight = -1, titleBarHeight = -1; int borderWidth = -1, borderHeight = -1, titleBarHeight = -1;
QVector<QRect> ignoreAreas = {}, draggableAreas = {}; QVector<QRect> ignoreAreas = {}, draggableAreas = {};
QVector<QPointer<QObject>> ignoreObjects = {}, draggableObjects = {}; QVector<QPointer<QObject>> ignoreObjects = {}, draggableObjects = {};