1. QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);
shadow_effect->setOffset(0, 2);
shadow_effect->setBlurRadius(8);
shadow_effect->setColor(QColor(0, 0, 0, 64));
ui->widget_bg->setGraphicsEffect(shadow_effect);
2.注意设置margin同SHADOW_W一样
void CTVBaseMenu::paintEvent(QPaintEvent* e)
{
QMenu::paintEvent(e);
const int SHADOW_W = 3;
QPainter painter(this);
QColor SHADOW_CLR("#29000000"); //暂时只有白色主题阴影
painter.setRenderHint(QPainter::Antialiasing, true);
for (int i = 0; i < SHADOW_W; ++i)
{
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRoundedRect(SHADOW_W - i, SHADOW_W - i,
this->width() - (SHADOW_W - i) * 2,
this->height() - (SHADOW_W - i) * 2,
SHADOW_W / 2, SHADOW_W / 2);
uint alpha = qPow(SHADOW_W - i, 2) * 5;
SHADOW_CLR.setAlpha(alpha > 255 ? 255 : alpha);
painter.setPen(SHADOW_CLR);
painter.drawPath(path);
}
}