哈喽,好久不见!今天要分享的内容是qt编写的窗口在windows系统下如何完美实现窗口边框阴影。
qt虽然自带阴影类QGraphicsDropShadowEffect,但是它的原理是需要两层widget,上面一层显示窗口,下面一层作为阴影。但是,如果产品经理反复横跳,刚开始不要阴影,后来又提出需求了,怎么办?这时你的窗口布局什么的全都弄好了,又不好修改。如何做到想加就加,想不要就不要呢?请往下看。
我们这里是使用的windows api做的,所以做全平台的就不能帮助啦。
首先,我们使用windows的dwmapi创建一个阴影类。
//*******************************************************h*******************************************
#ifndef WINDWMAPI_H
#define WINDWMAPI_H
#include <windows.h>
typedef struct _MARGINS
{
int cxLeftWidth; // width of left border that retains its size
int cxRightWidth; // width of right border that retains its size
int cyTopHeight; // height of top border that retains its size
int cyBottomHeight; // height of bottom border that retains its size
} MARGINS, *PMA