1、代码



void QJInterface::closeEvent(QCloseEvent *event)
{
QDialog* log = new QDialog(this);
log->setObjectName("log");
log->setStyleSheet("#log{background:#3379B7;}");
log->deleteLater();
log->setWindowTitle("退出平台");
log->resize(200,100);
// log->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
QLabel* lel = new QLabel(log);
lel->setText("确定退出平台吗?");
lel->setStyleSheet("QLabel{font-family:'宋体';font-size:20px;color:white;background:#3379B7;}");
lel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QPushButton* okBtn = new QPushButton(log);
QPushButton* clsBtn = new QPushButton(log);
okBtn->setStyleSheet("QPushButton{color: green;min-width:75px;max-width:75px;min-height:20px;border:1px solid white;border-radius:5px;}"
"QPushButton:hover{background-color: #333333;border-color: #444444;color:rgb(255,255,255);}"
"QPushButton:pressed{background-color: #111111;border-color: #333333;color: yellow;}");
clsBtn->setStyleSheet("QPushButton{color: green;min-width:75px;max-width:75px;min-height:20px;border:1px solid white;border-radius:5px;}"
"QPushButton:hover{background-color: #333333;border-color: #444444;color:rgb(255,255,255);}"
"QPushButton:pressed{background-color: #111111;border-color: #333333;color: yellow;}");
okBtn->setText("确定");
clsBtn->setText("取消");
okBtn->setMaximumWidth(100);
clsBtn->setMaximumWidth(100);

QObject::connect(okBtn,&QPushButton::clicked,[=]()
{
log->done(1);
});
QObject::connect(clsBtn,&QPushButton::clicked,[=]()
{
log->done(0);
});
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->setSpacing(5);
hLayout->addStretch();
hLayout->addWidget(okBtn);
hLayout->addWidget(clsBtn);
QVBoxLayout* v = new QVBoxLayout();
v->addWidget(lel);
v->addItem(hLayout);
log->setLayout(v);
if(1==log->exec())
{
event->accept();
}
else
{
event->ignore();
}
}


主要是重写closeEvent函数

 

长风破浪会有时,直挂云帆济沧海!