方法1:
YourClass::YourClass(QWidget *parent) :
{
QMessageBox msgbox = new QMessageBox(this);
msgbox->setGeometry(QRect(0, 0, 360, 300));
msgbox->addButton(tr("是"), QMessageBox::AcceptRole);
msgbox->addButton(tr("否"), QMessageBox::RejectRole);
msgbox->setText(tr("do you know thisisqt.com?"));
msgbox->exec();
}
方法2:
//最后一个参数必须是this,不能是nullptr,否则消息框会被其他的置顶对话框挡住
QMessageBox box(QMessageBox::Information, tr("提示"), info1, QMessageBox::Ok, this);
box.setStandardButtons(QMessageBox::Ok);
box.setButtonText(QMessageBox::Ok, tr("确定"));
box.exec();