From 0241ecd07fc516b7f3379f6185cb42be85c8d2ad Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Tue, 2 Jan 2024 14:53:53 +0800 Subject: [PATCH] update --- example/qml-Qt6/page/T_Settings.qml | 1 + example/qml/page/T_Settings.qml | 1 + src/FluFramelessHelper.cpp | 18 +++++++----------- .../imports/FluentUI/Controls/FluWindow.qml | 9 +++++---- .../imports/FluentUI/Controls/FluWindow.qml | 9 +++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/example/qml-Qt6/page/T_Settings.qml b/example/qml-Qt6/page/T_Settings.qml index 5668e737..04e7d0a7 100644 --- a/example/qml-Qt6/page/T_Settings.qml +++ b/example/qml-Qt6/page/T_Settings.qml @@ -67,6 +67,7 @@ FluScrollablePage{ anchors.verticalCenter: parent.verticalCenter onClicked: { FluApp.useSystemAppBar = !FluApp.useSystemAppBar + dialog_restart.open() } } } diff --git a/example/qml/page/T_Settings.qml b/example/qml/page/T_Settings.qml index b1390e64..d61429c0 100644 --- a/example/qml/page/T_Settings.qml +++ b/example/qml/page/T_Settings.qml @@ -70,6 +70,7 @@ FluScrollablePage{ anchors.verticalCenter: parent.verticalCenter onClicked: { FluApp.useSystemAppBar = !FluApp.useSystemAppBar + dialog_restart.open() } } } diff --git a/src/FluFramelessHelper.cpp b/src/FluFramelessHelper.cpp index 3bfc280e..3cef223c 100644 --- a/src/FluFramelessHelper.cpp +++ b/src/FluFramelessHelper.cpp @@ -154,6 +154,11 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void * } return false; }else if(uMsg == WM_NCPAINT){ + *result = 0; + return true; + } + else if(uMsg == WM_NCACTIVATE){ + *result = DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1); return true; } return false; @@ -273,7 +278,7 @@ void FluFramelessHelper::componentComplete(){ _appBarHeight = QQmlProperty(window,"_appBarHeight"); #ifdef Q_OS_WIN if(isCompositionEnabled()){ - window->setFlag(Qt::CustomizeWindowHint,true); + window->setFlags(Qt::Window|Qt::CustomizeWindowHint); _nativeEvent =new FramelessEventFilter(this); qApp->installNativeEventFilter(_nativeEvent); HWND hwnd = reinterpret_cast(window->winId()); @@ -284,6 +289,7 @@ void FluFramelessHelper::componentComplete(){ SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME); } SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); + }else{ window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window); } @@ -361,16 +367,6 @@ FluFramelessHelper::~FluFramelessHelper(){ if(isCompositionEnabled()){ qApp->removeNativeEventFilter(_nativeEvent); delete _nativeEvent; - HWND hwnd = reinterpret_cast(window->winId()); - SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); - int w = window->width(); - int h = window->height(); - if(_fixSize.read().toBool()){ - window->setMaximumSize(QSize(w,h)); - window->setMinimumSize(QSize(w,h)); - } - window->setWidth(w); - window->setHeight(h); } #endif window->removeEventFilter(this); diff --git a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml index a6b356d7..b90ef747 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluWindow.qml @@ -39,7 +39,7 @@ Window { property bool showMaximize: true property bool showStayTop: true property bool autoMaximize: false - property bool useSystemAppBar: FluApp.useSystemAppBar + property bool useSystemAppBar property color resizeBorderColor: { if(window.active){ return _accentColor @@ -70,9 +70,10 @@ Window { _realHeight = height _realWidth = width moveWindowToDesktopCenter() - loader_frameless_helper.sourceComponent = Qt.binding(function(){ - return window.useSystemAppBar ? undefined : com_frameless - }) + useSystemAppBar = FluApp.useSystemAppBar + if(!useSystemAppBar){ + loader_frameless_helper.sourceComponent = com_frameless + } lifecycle.onCompleted(window) initArgument(argument) if(window.autoMaximize){ diff --git a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml index ca3e5254..f6d7a9d0 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluWindow.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluWindow.qml @@ -38,7 +38,7 @@ Window { property bool showMaximize: true property bool showStayTop: true property bool autoMaximize: false - property bool useSystemAppBar: FluApp.useSystemAppBar + property bool useSystemAppBar property color resizeBorderColor: { if(window.active){ return _accentColor @@ -69,9 +69,10 @@ Window { _realHeight = height _realWidth = width moveWindowToDesktopCenter() - loader_frameless_helper.sourceComponent = Qt.binding(function(){ - return window.useSystemAppBar ? undefined : com_frameless - }) + useSystemAppBar = FluApp.useSystemAppBar + if(!useSystemAppBar){ + loader_frameless_helper.sourceComponent = com_frameless + } lifecycle.onCompleted(window) initArgument(argument) if(window.autoMaximize){