//添加阴影
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);
QPainter painter(this);
painter.setRenderHi

本文介绍如何在Qt中创建一个无边框窗口,并为其添加阴影效果。通过覆盖paintEvent方法,利用QPainter和QGraphicsDropShadowEffect来实现窗口的阴影效果。
最低0.47元/天 解锁文章
1320

被折叠的 条评论
为什么被折叠?



