QT QWidget设置圆角无效果
.qss内容:
QWidget {
border: none;
background-color: rgba(0, 0, 0, 204);
border-radius: 4px;
color: #FFFFFF;
}
原因:有二
原因一:
没有父窗口或者有popup等风格时, 只有background, background-clip and background-origin等会生效,
需要设置:
void Widget::paintEvent(QPaintEvent *event)
QStyleOption opt;
opt.init(this);
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
}
原因二:圆角被背景覆盖了
需要设置半透明背景
setAttribute(Qt::WA_TranslucentBackground);