QMessageBox::warning(this,tr("警告信息"),tr("用户确认警告信息"));
QMessageBox::critical(this,"错误信息","用户确认错误信息");
QMessageBox::information(this,"提示信息","用户确认信息");
QMessageBox::question(this,"提示信息","用户确认信息");
QMessageBox::question(this,"提示信息","用户确认信息");
QMessageBox第四个参数自定义需要显示的按钮,可以是一个,两个,三个按钮,第五个参数设置弹出时选择的按钮,以下选择Yes.
QMessageBox::information(this, "提示信息", "用户确认信息",
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QMessageBox::information(NULL, "提示信息", "用户确认信息",
QMessageBox::Yes|QMessageBox::No|QMessageBox::Abort);
QMessageBox:: StandardButton result= QMessageBox::information(this, "提示信息", "用户确认信息",QMessageBox::Yes|QMessageBox::No);
switch (result)
{
case QMessageBox::Yes:
qDebug()<<"选择Yes操作";
break;
case QMessageBox::No:
qDebug()<<"选择NO操作";
break;
default:
break;
}
or
QMessageBox messageBox(QMessageBox::NoIcon,
"退出", "你确定要退出吗?",
QMessageBox::Yes | QMessageBox::No, NULL); ;
int result=messageBox.exec();
switch (result)
{
case QMessageBox::Yes:
qDebug()<<"Yes";
close();
break;
case QMessageBox::No:
qDebug()<<"NO";
break;
default:
break;
}
QMessageBox msgBox;
msgBox.setText(tr("提示信息"));
msgBox.setStyleSheet("QLabel{min-width: 700px;min-height: 200px;"
"background-color: qlineargradient(x1: 0, y1: 1, x2: 0, y2: 0,stop: 0 rgba(255, 255, 255, 100%),stop: 1 rgba(246, 49, 34, 100%));"
"color:rgba(255, 255, 255, 255);"
"font-size:20px; }");
msgBox.exec();
enum StandardButton {
// keep this in sync with QDialogButtonBox::StandardButton
NoButton = 0x00000000,
Ok = 0x00000400,
Save = 0x00000800,
SaveAll = 0x00001000,
Open = 0x00002000,
Yes = 0x00004000,
YesToAll = 0x00008000,
No = 0x00010000,
NoToAll = 0x00020000,
Abort = 0x00040000,
Retry = 0x00080000,
Ignore = 0x00100000,
Close = 0x00200000,
Cancel = 0x00400000,
Discard = 0x00800000,
Help = 0x01000000,
Apply = 0x02000000,
Reset = 0x04000000,
RestoreDefaults = 0x08000000,
FirstButton = Ok, // internal
LastButton = RestoreDefaults, // internal
YesAll = YesToAll, // obsolete
NoAll = NoToAll, // obsolete
Default = 0x00000100, // obsolete
Escape = 0x00000200, // obsolete
FlagMask = 0x00000300, // obsolete
ButtonMask = ~FlagMask // obsolete
};