int width1 = this->width();
int height1 = this->height();
QWidget *m_mask = new QWidget(this);
m_mask->resize (width1, height1);
m_mask->move (0,0);
m_mask->setWindowFlags(Qt::FramelessWindowHint);
m_mask->setAttribute(Qt::WA_StyledBackground);
m_mask->setStyleSheet("");
int width2 = 520;
int height2 = 280;
QDialog *m_widget = new QDialog(this);
m_widget->setWindowFlags(Qt::FramelessWindowHint);
m_widget->setAttribute(Qt::WA_StyledBackground);
m_widget->resize(width2,height2);
m_widget->move((width1-width2)/2,(height1-height2)/2);
QLabel *bg = new QLabel(m_widget);
bg->resize(width2,height2);
//bg->move((width1-width2)/2,(height1-height2)/2);
bg->setPixmap(QPixmap(":/image_normal/bg_tip_warn.png"));
QFont font;
font.setFamily(FONT_B);
font.setPixelSize(30);
QLabel *title = new QLabel(bg);
//title->setAlignment(Qt::AlignCenter);
title->setGeometry(251,14,64,42);
title->setText(QStringLiteral("提示"));
title->setFont(font);
title->setStyleSheet("color:rgb(255,255,255);"> transparent;");
//title->setStyleSheet("QLabel{color:rgb(255,255,255);"> transparent;}");
font.setFamily(FONT_M);
font.setPixelSize(24);
QLabel *lab_text = new QLabel(bg);
lab_text->resize(width2,99);
lab_text->move(0,85);
lab_text->setAlignment(Qt::AlignHCenter);
lab_text->setText(text);
lab_text->setFont(font);
lab_text->setWordWrap(true);
title->setStyleSheet("color:rgb(255,255,255);");
//lab_text->setStyleSheet("QLabel{color:rgb(38,38,38);"> transparent;}");
//m_widget->show();
QPushButton* btn_ok=new QPushButton(bg);
btn_ok->resize(150,50);
btn_ok->move(188,195);
btn_ok->setFont(font);
btn_ok->setStyleSheet("QPushButton{color:rgb(255,255,255);}");
btn_ok->setText(QStringLiteral("确定"));
connect(btn_ok,&QPushButton::clicked,m_widget,&QDialog::accept);
m_mask->show();
int nRes = m_widget->exec();
if (nRes == QDialog::Accepted)
{
m_widget->deleteLater();
m_mask->deleteLater();
}标签:widget,qt,title,text,QLabel,dialog,font,变暗,255 From: https://www.cnblogs.com/clive-ccc/p/16779511.html