QMessageBox 模态框
void MainWindow::on_pushButton_clicked() { QMessageBox *msgbox_ = new QMessageBox(this); msgbox_->setWindowTitle(tr("模态框")); msgbox_->setWindowModality(Qt::WindowModal); //通过这个 然后下面可以用show 实现模态框 msgbox_->setWindowFlags(msgbox_->windowFlags() | Qt::Sheet); msgbox_->setStandardButtons(QMessageBox::Ok); msgbox_->setIcon(QMessageBox::Warning); msgbox_->setText("提示内容"); msgbox_->show(); //结合上面的setWindowModality(Qt::WindowModal) //msgbox_->exec();//可以直接使用exec来实现模态框 }