RibbonWindow: Enable blur behind window for Windows.

This commit is contained in:
Mentalflow 2024-04-21 13:26:46 +08:00
parent 3e0e94a2a5
commit 863c61325a
Signed by: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
5 changed files with 16 additions and 10 deletions

View File

@ -21,7 +21,7 @@ BEGIN
BEGIN BEGIN
VALUE "Comments", "Made by Mentalflow." VALUE "Comments", "Made by Mentalflow."
VALUE "CompanyName", "${PROJECT_COMPANY}" VALUE "CompanyName", "${PROJECT_COMPANY}"
VALUE "FileDescription", "${PROJECT_COPYRIGHT}" VALUE "FileDescription", "${PROJECT_BUNDLE_NAME}"
VALUE "FileVersion", "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" VALUE "FileVersion", "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
VALUE "InternalName", "${PROJECT_BUNDLE_NAME}.exe" VALUE "InternalName", "${PROJECT_BUNDLE_NAME}.exe"
VALUE "LegalCopyright", "${PROJECT_COPYRIGHT}" VALUE "LegalCopyright", "${PROJECT_COPYRIGHT}"

View File

@ -7,8 +7,7 @@ RibbonWindow {
id: window id: window
width: Math.max(content.width, content.height + title_bar.height, title_bar.minimumWidth) + content.anchors.margins * 2 width: Math.max(content.width, content.height + title_bar.height, title_bar.minimumWidth) + content.anchors.margins * 2
minimumWidth: title_bar.minimumWidth minimumWidth: title_bar.minimumWidth
minimumHeight: content.height + title_bar.height minimumHeight: content.height + title_bar.height + content.anchors.margins * 2
height: width
title: qsTr("About") title: qsTr("About")
title_bar.show_darkmode_btn: false title_bar.show_darkmode_btn: false
title_bar.show_style_switch: false title_bar.show_style_switch: false

View File

@ -21,6 +21,9 @@ if(APPLE)
endif() endif()
if (RIBBONUI_BUILD_QWINDOWKIT) if (RIBBONUI_BUILD_QWINDOWKIT)
if(WIN32)
set(QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS OFF)
endif()
set(QWINDOWKIT_BUILD_STATIC ON) set(QWINDOWKIT_BUILD_STATIC ON)
set(QWINDOWKIT_BUILD_EXAMPLES OFF) set(QWINDOWKIT_BUILD_EXAMPLES OFF)
set(QWINDOWKIT_BUILD_QUICK ON) set(QWINDOWKIT_BUILD_QUICK ON)

View File

@ -16,7 +16,7 @@ Window {
property alias title_bar: titleBar property alias title_bar: titleBar
property alias popup: pop property alias popup: pop
property bool comfirmed_quit: false property bool comfirmed_quit: false
property bool blurBehindWindow: false property bool blurBehindWindow: true
visible: false visible: false
color: { color: {
if (blurBehindWindow) { if (blurBehindWindow) {
@ -29,7 +29,7 @@ Window {
} }
onBlurBehindWindowChanged: { onBlurBehindWindowChanged: {
if (Qt.platform.os === 'windows') if (Qt.platform.os === 'windows')
windowAgent.setWindowAttribute("acrylic-material", blurBehindWindow) windowAgent.setWindowAttribute("mica", blurBehindWindow)
else if (Qt.platform.os === 'osx') else if (Qt.platform.os === 'osx')
windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.dark_mode ? "dark" : "light" : "none") windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.dark_mode ? "dark" : "light" : "none")
} }
@ -38,22 +38,23 @@ Window {
windowAgent.setup(window) windowAgent.setup(window)
if (Qt.platform.os === 'windows') if (Qt.platform.os === 'windows')
{ {
windowAgent.setWindowAttribute("acrylic-material", blurBehindWindow) windowAgent.setWindowAttribute("mica", blurBehindWindow)
windowAgent.setSystemButton(WindowAgent.Minimize, titleBar.minimizeBtn); windowAgent.setSystemButton(WindowAgent.Minimize, titleBar.minimizeBtn);
windowAgent.setSystemButton(WindowAgent.Maximize, titleBar.maximizeBtn); windowAgent.setSystemButton(WindowAgent.Maximize, titleBar.maximizeBtn);
windowAgent.setSystemButton(WindowAgent.Close, titleBar.closeBtn); windowAgent.setSystemButton(WindowAgent.Close, titleBar.closeBtn);
} }
if(Qt.platform.os === "osx") if(Qt.platform.os === "osx")
{ {
blurBehindWindow = true
windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.dark_mode ? "dark" : "light" : "none") windowAgent.setWindowAttribute("blur-effect", blurBehindWindow ? RibbonTheme.dark_mode ? "dark" : "light" : "none")
PlatformSupport.showSystemTitleBtns(window, true) PlatformSupport.showSystemTitleBtns(window, true)
} }
windowAgent.setHitTestVisible(titleBar.left_container) windowAgent.setHitTestVisible(titleBar.left_container)
windowAgent.setHitTestVisible(titleBar.right_container) windowAgent.setHitTestVisible(titleBar.right_container)
windowAgent.setTitleBar(titleBar); windowAgent.setTitleBar(titleBar)
windowAgent.centralize() windowAgent.centralize()
window.visible = true; window.flags ^= Qt.WA_AlwaysShowToolTips // It's a trick for Windows
window.visible = true
window.flags ^= Qt.WA_AlwaysShowToolTips // It's a trick for Windows
} }
Item{ Item{
id: window_items id: window_items
@ -98,7 +99,7 @@ Window {
color: 'transparent' color: 'transparent'
border.color: RibbonTheme.dark_mode ? "#7A7A7A" : "#2C59B7" border.color: RibbonTheme.dark_mode ? "#7A7A7A" : "#2C59B7"
border.width: RibbonTheme.modern_style ? 1 : 0 border.width: RibbonTheme.modern_style ? 1 : 0
radius: Qt.platform.os === 'windows' ? 8 : 10 radius: Qt.platform.os === 'windows' ? 7 : 10
visible: RibbonTheme.modern_style visible: RibbonTheme.modern_style
} }
RibbonPopup{ RibbonPopup{

View File

@ -32,6 +32,9 @@ void RibbonUI::init()
qputenv("QT_QUICK_CONTROLS_STYLE", "Basic"); qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
#else #else
qputenv("QT_QUICK_CONTROLS_STYLE", "Default"); qputenv("QT_QUICK_CONTROLS_STYLE", "Default");
#endif
#ifdef Q_OS_WIN
qputenv("QSG_RHI_BACKEND", "opengl");
#endif #endif
QQuickWindow::setDefaultAlphaBuffer(true); QQuickWindow::setDefaultAlphaBuffer(true);
} }