LoRd_MuldeR
13th December 2021, 01:00
Does anybody know how to get a proper "glass" effect on Windows 11?
Every since Windows 7, I have been using this code to enable the "glass" effect on a window:
bool MUtils::GUI::sheet_of_glass(QWidget *const window)
{
/* Code to load "dwmapi.dll" and look up the required functions is excluded*/
//Enable the "sheet of glass" effect on this window
MARGINS margins = {-1, -1, -1, -1};
if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(reinterpret_cast<HWND>(window->winId()), &margins))
{
qWarning("DwmExtendFrameIntoClientArea function has failed! (error %d)", hr);
return false;
}
//Create and populate the Blur Behind structure
DWM_BLURBEHIND bb;
memset(&bb, 0, sizeof(DWM_BLURBEHIND));
bb.fEnable = TRUE;
bb.dwFlags = DWM_BB_ENABLE;
if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast<HWND>(window->winId()), &bb))
{
qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
return false;
}
//Required for Qt
window->setAutoFillBackground(false);
window->setAttribute(Qt::WA_TranslucentBackground);
window->setAttribute(Qt::WA_NoSystemBackground);
return true;
}
Result on Windows 7 looks like this:
https://i.imgur.com/P61ZnfK.png :cool:
Windows 8.1 and Windows 10 still looks sort of "okay":
https://i.imgur.com/Cfn1Dii.png :o
But on Windows 11 it looks like... that:
https://i.imgur.com/7UJwwxW.png :scared:
So, background is just not rendered at all on Windows 11, making the window totally transparent and looking kind of "broken". Any idea why that is?
What I'd actually like to have is a semi-transparent "smoked glass" effect, as in the Windows 11 startmenu and settings menus:
https://i.imgur.com/J1YaQlH.png
Every since Windows 7, I have been using this code to enable the "glass" effect on a window:
bool MUtils::GUI::sheet_of_glass(QWidget *const window)
{
/* Code to load "dwmapi.dll" and look up the required functions is excluded*/
//Enable the "sheet of glass" effect on this window
MARGINS margins = {-1, -1, -1, -1};
if(HRESULT hr = dwmExtendFrameIntoClientAreaFun(reinterpret_cast<HWND>(window->winId()), &margins))
{
qWarning("DwmExtendFrameIntoClientArea function has failed! (error %d)", hr);
return false;
}
//Create and populate the Blur Behind structure
DWM_BLURBEHIND bb;
memset(&bb, 0, sizeof(DWM_BLURBEHIND));
bb.fEnable = TRUE;
bb.dwFlags = DWM_BB_ENABLE;
if(HRESULT hr = dwmEnableBlurBehindWindowFun(reinterpret_cast<HWND>(window->winId()), &bb))
{
qWarning("DwmEnableBlurBehindWindow function has failed! (error %d)", hr);
return false;
}
//Required for Qt
window->setAutoFillBackground(false);
window->setAttribute(Qt::WA_TranslucentBackground);
window->setAttribute(Qt::WA_NoSystemBackground);
return true;
}
Result on Windows 7 looks like this:
https://i.imgur.com/P61ZnfK.png :cool:
Windows 8.1 and Windows 10 still looks sort of "okay":
https://i.imgur.com/Cfn1Dii.png :o
But on Windows 11 it looks like... that:
https://i.imgur.com/7UJwwxW.png :scared:
So, background is just not rendered at all on Windows 11, making the window totally transparent and looking kind of "broken". Any idea why that is?
What I'd actually like to have is a semi-transparent "smoked glass" effect, as in the Windows 11 startmenu and settings menus:
https://i.imgur.com/J1YaQlH.png