实现效果
为了更清晰的看到阴影,故这里采用红色的阴影。
思路
1、使用QGraphicsDropShadowEffect类生成阴影
2、在QDialog中放入一个Widget,让Wdiget产生阴影
3、使QDialog本身的窗口透明
关键代码
void Dialog::iniShadow()
{
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());//去掉标题栏
this->setAttribute(Qt::WA_TranslucentBackground, true);//使得窗口透明
QWidget *pW = new QWidget(this);
pW->setGeometry(10,10,this->width() - 20,this->height() - 20);
pW->setStyleSheet("QWidget{background-color:rgb(52,52,52);border-radius:5px;}");
QGraphicsDropShadowEffect *pShadow = new QGraphicsDropShadowEffect(this);
pShadow->setOffset(0,0); //阴影偏移位置
pShadow->setColor(Qt::red); //阴影的颜色
pShadow->setBlurRadius(20);//阴影的范围
pW->setGraphicsEffect(pShadow);
}