我在开发Qt Windows程序时,加入玻璃化效果
#ifdef _SAFE_BROWSER_ENABLE_GLASS_EFFECT
#include <dwmapi.h>
// WARNING: disable -O2, or application will CRASH at startup!!
void setGlassEffect(QWidget *w)
{
typedef HRESULT (STDAPICALLTYPE *enableBlurBehindWindow)(HWND, const DWM_BLURBEHIND *);
typedef HRESULT (STDAPICALLTYPE *extendFrameIntoClientArea)(HWND, MARGINS *);
enableBlurBehindWindow f1 =
(enableBlurBehindWindow)QLibrary::resolve("dwmapi", "DwmEnableBlurBehindWindow");
extendFrameIntoClientArea f2 =
(extendFrameIntoClientArea)QLibrary::resolve("dwmapi", "DwmExtendFrameIntoClientArea");
DWM_BLURBEHIND bb = {0};
MARGINS margins = {-1};
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
if(f1)f1(w->winId(), &bb);
if(f2)f2(w->winId(), &margins);
}
#endif
注意还需要在Widget中修改paintEvent