- 使用前引用头文件 #include <QMessageBox>
- 如要使用中文需要使用 QString::fromLocal8Bit 来转换
- QMessageBox支持6种类型的消息框,包含自定义的
information:
QMessageBox::information(this,
"Information",
"this is informations");
critical:
QMessageBox::critical(this,
"Critical",
"this is Critical text");
question:
QMessageBox::question(this,
"Question",
"this is an question ?",
QMessageBox::Ok,
QMessageBox::Cancel);
warning:
QMessageBox::warning(this,
"Warning",
"this is an warning content!");
about:
QMessageBox::about(this,
"About",
"this is an ablut text");
自定义:
QMessageBox msg(QMessageBox::NoIcon,
"CustMsg",
"this is an custom msg",
QMessageBox::Yes|
QMessageBox::No|
QMessageBox::Cancel);
msg.setIcon(QMessageBox::Critical);
msg.setWindowTitle(CH("自定义消息框"));
msg.setText(CH("这是自定义消息框的内容!"));;
msg.setDefaultButton(QMessageBox::Yes);//默认按钮
int m = msg.exec();
switch(m){
case QMessageBox::Yes:
qDebug()<<CH("选择了Yes");
break;
case QMessageBox::No:
qDebug()<<CH("选择了No");
break;
case QMessageBox::Cancel:
qDebug()<<CH("选择了Cancel");
break;
default:
break;
}
标签:实战,Qt5.12,自定义,question,Critical,QMessageBox,msg,warning
From: https://blog.51cto.com/remotedev/6149144