//添加阴影
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this);
shadow->setOffset(0, 0);
shadow->setColor(QColor("#444444"));
shadow->setBlurRadius(30);
setGraphicsEffect(shadow);
QHBoxLayout* dashi_login_layout = new QHBoxLayout();
dashi_login_layout->addWidget(main_frame_);
dashi_login_layout->setSpacing(0);
//阴影宽度(很重要,否则阴影不显示)
dashi_login_layout->setMargin(15);
setLayout(dashi_login_layout);
二:paintEvent
void WindowBaseDrag::paintEvent(QPaintEvent* event) {
int nShadowsWidth = 10; // 阴影宽度
int nRadius = 10; // 圆角宽度
QPainterPath path;
path.setFillRule(Qt::WindingFill);
path.addRoundedRect(
nShadowsWidth, nShadowsWidth, width() - nShadowsWidth * 2,
height() - nShadowsWidth * 2, nRadius, nRadius);