From 4eac2b29704a44f89e7fa4f3a51fae5ce0951893 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 6 Apr 2022 13:15:29 +0800 Subject: [PATCH] implement TransparentWindowBackground option Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- .../FramelessHelper/Core/framelesshelpercore_global.h | 2 +- src/quick/framelessquickwindow.cpp | 9 ++++++--- src/widgets/framelesswidgetshelper.cpp | 8 ++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index 682b154..d5f5e75 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -192,7 +192,7 @@ enum class Option : int ForceShowWindowFrameBorder = 0x00000002, // Windows only, force show the window frame border even on Windows 7 (~ 8.1). DontDrawTopWindowFrameBorder = 0x00000004, // Windows only, don't draw the top window frame border even if the window frame border is visible. EnableRoundedWindowCorners = 0x00000008, // Not implemented yet. - TransparentWindowBackground = 0x00000010, // Not implemented yet. + TransparentWindowBackground = 0x00000010, // Make the window's background become transparent. MaximizeButtonDocking = 0x00000020, // Not implemented yet. CreateStandardWindowLayout = 0x00000040, // Using this option will cause FramelessHelper create a homemade titlebar and a window layout to contain it. If your window has a layout already, the newly created layout will mess up your own layout. BeCompatibleWithQtFramelessWindowHint = 0x00000080, // Windows only, make the code compatible with Qt::FramelessWindowHint. Don't use this option unless you really need that flag. diff --git a/src/quick/framelessquickwindow.cpp b/src/quick/framelessquickwindow.cpp index 8d08fad..2cedd58 100644 --- a/src/quick/framelessquickwindow.cpp +++ b/src/quick/framelessquickwindow.cpp @@ -406,6 +406,12 @@ void FramelessQuickWindowPrivate::initialize() m_params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool { return isInSystemButtons(pos, button); }; m_params.isInsideTitleBarDraggableArea = [this](const QPoint &pos) -> bool { return isInTitleBarDraggableArea(pos); }; m_params.getWindowDevicePixelRatio = [q]() -> qreal { return q->effectiveDevicePixelRatio(); }; + if (m_settings.options & Option::DisableResizing) { + setFixedSize(true, true); + } + if (m_settings.options & Option::TransparentWindowBackground) { + q->setColor(kDefaultTransparentColor); + } FramelessWindowsManager * const manager = FramelessWindowsManager::instance(); manager->addWindow(m_settings, m_params); q->installEventFilter(this); @@ -445,9 +451,6 @@ void FramelessQuickWindowPrivate::initialize() m_topBorderAnchors->setTop(rootItemPrivate->top()); m_topBorderAnchors->setLeft(rootItemPrivate->left()); m_topBorderAnchors->setRight(rootItemPrivate->right()); - if (m_settings.options & Option::DisableResizing) { - setFixedSize(true, true); - } } QRect FramelessQuickWindowPrivate::mapItemGeometryToScene(const QQuickItem * const item) const diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index acdf10f..45c9d63 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -393,6 +393,9 @@ void FramelessWidgetsHelper::initialize() " Enabling this option will mess up with your main window's layout."; } } + if (m_settings.options & Option::TransparentWindowBackground) { + m_settings.options |= Option::BeCompatibleWithQtFramelessWindowHint; + } if (m_settings.options & Option::DisableResizing) { setFixedSize(true, true); } @@ -400,6 +403,11 @@ void FramelessWidgetsHelper::initialize() Utils::tryToBeCompatibleWithQtFramelessWindowHint(windowId, m_params.getWindowFlags, m_params.setWindowFlags, true); } + if (m_settings.options & Option::TransparentWindowBackground) { + q->setWindowFlags(q->windowFlags() | Qt::FramelessWindowHint); + q->setAttribute(Qt::WA_NoSystemBackground); + q->setAttribute(Qt::WA_TranslucentBackground); + } FramelessWindowsManager * const manager = FramelessWindowsManager::instance(); manager->addWindow(m_settings, m_params); q->installEventFilter(this);