class QtWidgetsApplication5 : public QDialog
{
Q_OBJECT
public:
QtWidgetsApplication5(QWidget *parent = Q_NULLPTR)
: QDialog(parent)
{
ui.setupUi(this);
this->setAttribute(Qt::WA_TranslucentBackground);//设置窗口背景透明
this->setWindowFlags(Qt::FramelessWindowHint); //设置无边框窗口
}
void paintEvent(QPaintEvent *event) override
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setBrush(QBrush(Qt::red));
painter.setPen(Qt::black);
QRect rect = this->rect();
rect.setWidth(rect.width() - 1);
rect.setHeight(rect.height() - 1);
painter.drawRoundedRect(rect, 15, 15);
/* QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
this->setStyleSheet("{background-color:transparent; }");*/
QDialog::paintEvent(event);
}
private:
Ui::QtWidgetsApplication5Class ui;
};