forked from github_mirror/framelesshelper
Fix the acrylic effect.
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
ff4556438b
commit
226bc52ece
|
@ -96,12 +96,7 @@ Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
||||||
updateWindow(this);
|
updateWindow(this);
|
||||||
});
|
});
|
||||||
connect(ui->blurEffectCB, &QCheckBox::stateChanged, this, [this](int state) {
|
connect(ui->blurEffectCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||||
const bool enable = state == Qt::Checked;
|
WinNativeEventFilter::setBlurEffectEnabled(getRawHandle(this), state == Qt::Checked);
|
||||||
QPalette palette = {};
|
|
||||||
// Choose the gradient color you like.
|
|
||||||
palette.setColor(QPalette::Window, QColor(255, 255, 255, 220));
|
|
||||||
setPalette(enable ? palette : QPalette());
|
|
||||||
WinNativeEventFilter::setBlurEffectEnabled(getRawHandle(this), enable);
|
|
||||||
updateWindow(this);
|
updateWindow(this);
|
||||||
});
|
});
|
||||||
connect(ui->resizableCB, &QCheckBox::stateChanged, this, [this](int state) {
|
connect(ui->resizableCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||||
|
|
|
@ -2357,14 +2357,28 @@ bool WinNativeEventFilter::displaySystemMenu(void *handle,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WinNativeEventFilter::setBlurEffectEnabled(void *handle, const bool enabled)
|
bool WinNativeEventFilter::setBlurEffectEnabled(void *handle,
|
||||||
|
const bool enabled,
|
||||||
|
const QColor &gradientColor)
|
||||||
{
|
{
|
||||||
Q_ASSERT(handle);
|
Q_ASSERT(handle);
|
||||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||||
|
#ifdef QT_WIDGETS_LIB
|
||||||
|
// Is it possible to set a palette to a QWindow?
|
||||||
|
QWidget *widget = QWidget::find(reinterpret_cast<WId>(hwnd));
|
||||||
|
if (widget && widget->isTopLevel()) {
|
||||||
|
// Qt will paint a solid white background to the window,
|
||||||
|
// it will cover the blurred effect, so we need to
|
||||||
|
// make the background become totally transparent. Achieve
|
||||||
|
// this by setting a palette to the window.
|
||||||
|
widget->setPalette(enabled ? QPalette(QColor(0, 0, 0, 0)) : QPalette());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (isWin8OrGreater() && coreData()->m_lpSetWindowCompositionAttribute) {
|
if (isWin8OrGreater() && coreData()->m_lpSetWindowCompositionAttribute) {
|
||||||
ACCENT_POLICY accentPolicy;
|
ACCENT_POLICY accentPolicy;
|
||||||
SecureZeroMemory(&accentPolicy, sizeof(accentPolicy));
|
SecureZeroMemory(&accentPolicy, sizeof(accentPolicy));
|
||||||
|
accentPolicy.GradientColor = gradientColor.rgba();
|
||||||
WINDOWCOMPOSITIONATTRIBDATA wcaData;
|
WINDOWCOMPOSITIONATTRIBDATA wcaData;
|
||||||
SecureZeroMemory(&wcaData, sizeof(wcaData));
|
SecureZeroMemory(&wcaData, sizeof(wcaData));
|
||||||
wcaData.Attrib = WCA_ACCENT_POLICY;
|
wcaData.Attrib = WCA_ACCENT_POLICY;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "framelesshelper_global.h"
|
#include "framelesshelper_global.h"
|
||||||
#include <QAbstractNativeEventFilter>
|
#include <QAbstractNativeEventFilter>
|
||||||
|
#include <QColor>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
|
||||||
|
@ -141,7 +142,9 @@ public:
|
||||||
|
|
||||||
// Enable or disable the blur effect for a specific window.
|
// Enable or disable the blur effect for a specific window.
|
||||||
// On Win10 it's the Acrylic effect.
|
// On Win10 it's the Acrylic effect.
|
||||||
static bool setBlurEffectEnabled(void *handle /* HWND */, const bool enabled = true);
|
static bool setBlurEffectEnabled(void *handle /* HWND */,
|
||||||
|
const bool enabled = true,
|
||||||
|
const QColor &gradientColor = QColor(255, 255, 255, 0));
|
||||||
|
|
||||||
// Thin wrapper of DwmExtendFrameIntoClientArea().
|
// Thin wrapper of DwmExtendFrameIntoClientArea().
|
||||||
static void updateFrameMargins(void *handle /* HWND */);
|
static void updateFrameMargins(void *handle /* HWND */);
|
||||||
|
|
Loading…
Reference in New Issue