implement TransparentWindowBackground option

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-06 13:15:29 +08:00
parent e19dad5b82
commit 4eac2b2970
3 changed files with 15 additions and 4 deletions

View File

@ -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.

View File

@ -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

View File

@ -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);