不能使用样式表。需要设置WA_TranslucentBackground属性后,使用paintevent手动自己画。
WLoading::WLoading(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
setAttribute(Qt::WA_TranslucentBackground);
}
void WLoading::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.save();
int m_border = 5;
QRect rect1 = this->rect();
rect1.setLeft(this->rect().left() + m_border);
rect1.setTop(this->rect().top() + m_border);
rect1.setRight(this->rect().right() - m_border);
rect1.setBottom(this->rect().bottom() - m_border);
painter.fillRect(rect1, QColor(0, 28, 32, 200));
}