QPushButton *okbtn = new QPushButton(QString::fromLocal8Bit("确定")); QPushButton *cancelbtn = new QPushButton(QString::fromLocal8Bit("取消")); QMessageBox *mymsgbox = new QMessageBox; //mymsgbox->setIcon(QMessageBox::Warning); mymsgbox->setWindowTitle(QString::fromLocal8Bit("提示")); mymsgbox->setText(QString::fromLocal8Bit("确定退出吗?")); mymsgbox->addButton(okbtn, QMessageBox::AcceptRole); mymsgbox->addButton(cancelbtn, QMessageBox::RejectRole); mymsgbox->setWindowFlags(Qt::widget); //mymsgbox->setWindowFlags(Qt::FramelessWindowHint); //mymsgbox->setWindowFlags(Qt::WindowSystemMenuHint ); mymsgbox->setWindowFlags(Qt::WindowStaysOnTopHint); mymsgbox->show(); mymsgbox->exec(); //阻塞等待用户输入 if (mymsgbox->clickedButton()==okbtn) { this->close(); } else{ }