Two ways of message dialog :

* ① For simple informational tips , Nothing else , Do not use the return value of the dialog
* ② Used to confirm the selection dialog box , Use the return value of dialog box

from warning(),information(),critical(),about() These functions make up , The parameters and usage of these functions are the same , It's just that the icons don't look the same , Below warning() Function as an example

Function prototype I :
int QMessageBox::warning( QWidget *parent, const QString &title, const QString
&text, int button0, int button1, int button2 = 0 )
* parent parameter : parent window
* title parameter : Message dialog title
* text parameter : Contents of message dialog box
*
button0,button1,button2 parameter : Exit type of button , The following types can be selected ( Default from left to right , If all defaults , The default is QMessageBox::Ok)

* Return value : Value of the exit button type selected for you ( Is the button constant value in the figure above )
Function prototype II :
int QMessageBox::warning(QWidget *parent, const QString &title, const QString
&text, const QString &button0Text, const QString &button1Text = QString(),
const QString &button2Text = QString(), int defaultButtonNumber = 0, int
escapeButtonNumber = -1)
* parent,title,text parameter : Same as above
* button0Text,button1Text,button2Text parameter : Select button for exit , Button text can be customized ( But it can be defaulted , All defaults to
QMessageBox::Ok). If it's all set button The serial number of is 0,1,2
*
defaultButtonNumber parameter : After the message dialog is displayed , The cursor stays in the front one by default button above ( Can be selected as the front button No , If the default is 0)
* Return value : Value of the exit button type selected for you ( namely button No. of )
One , Simple information tips

* concept : Message dialog QMessageBox Used to display prompts , warning , Error and other information , Or confirm the selection , Don't care about the return value of the dialog
Demo case

//Critical Button void Widget::on_btnMsgCritical_clicked() { QString
dlgTitle=QStringLiteral("critical message box "); QString
strInfo=QStringLiteral(" Unknown program accessing the network ");
QMessageBox::warning(this,dlgTitle,strInfo,
QStringLiteral(" determine "),QStringLiteral(" cancel "),QStringLiteral(" sign out "),2); }
//Informatio Button void Widget::on_btnMsgInformation_clicked() { QString
dlgTitle=QStringLiteral("information message box "); QString
strInfo=QStringLiteral(" file already open , Font size set ");
QMessageBox::warning(this,dlgTitle,strInfo,
QMessageBox::Yes,QMessageBox::No,QMessageBox::Cancel); } //Warnin Button void
Widget::on_btnMsgWarning_clicked() { QString
dlgTitle=QStringLiteral("warning message box "); QString
strInfo=QStringLiteral(" The contents of the file have been modified ");
QMessageBox::warning(this,dlgTitle,strInfo); } //About Button void
Widget::on_btnMsgAbout_clicked() { QString
dlgTitle=QStringLiteral("aboutg message box "); QString
strInfo=QStringLiteral(" Data viewing software developed by me V1.0\n All rights reserved ");
QMessageBox::warning(this,dlgTitle,strInfo); }
Two , Use as confirmation selection dialog

* Perform different operations according to the return value of the dialog box .
* The return value type of the dialog box can be QMessageBox::StandardButton express
* be careful : parameter 4 It can be done in a logical or way
Demo case : 

void Widget::on_btnMsgQuestion_clicked() { QString
dlgTitle=QStringLiteral("Question message box "); QString
strInfo=QStringLiteral(" File has been modified , Save changes or not "); QMessageBox::StandardButton
defaultBtn=QMessageBox::NoButton; QMessageBox::StandardButton result;
result=QMessageBox::question(this,dlgTitle,strInfo,
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,defaultBtn);
if(result==QMessageBox::Yes)
ui->plainTextEdit->appendPlainText(QStringLiteral("Yes Selected !")); else
if(result==QMessageBox::No)
ui->plainTextEdit->appendPlainText(QStringLiteral("No Selected !")); else
if(result==QMessageBox::Cancel)
ui->plainTextEdit->appendPlainText(QStringLiteral("Cancel Selected !")); else
ui->plainTextEdit->appendPlainText(QStringLiteral(" No choice !")); }
Three , Custom dialog click button text

Code design  
int result; QMessageBox *msgbox = new QMessageBox();
msgbox->setText(" Choose payment method "); // Set text
msgbox->setStandardButtons(QMessageBox::Yes|QMessageBox::No);// The settings dialog has several buttons
// Set button text msgbox->button(QMessageBox::Yes)->setText(" Alipay ");
msgbox->button(QMessageBox::No)->setText(" WeChat ");
result=msgbox->exec();// Execution dialog , And get the return value // According to QMessageBox The return value of shows different pictures QLabel*
label; if(result==QMessageBox::Yes){ QString
filename(":/pictures/src/zhi.png"); QImage* img=new QImage;
if((img->load(filename))) // Load image { label=new QLabel();
label->setPixmap(QPixmap::fromImage(*img)); label->setScaledContents(true);
label->setMaximumSize(547,662); label->show(); } } else
if(result==QMessageBox::No){ QString filename(":/pictures/src/wei.png");
QImage* img=new QImage; if((img->load(filename))) // Load image { label=new QLabel();
label->setPixmap(QPixmap::fromImage(*img)); label->setScaledContents(true);
label->setMaximumSize(547,662); label->show(); } }
Demonstration effect

* Click recharge button , Generate a dialog
 

Technology
©2019-2020 Toolsou All rights reserved,
QCustomPlot series (5)- Real time dynamic curve python To solve the problem of dictionary writing list in GDOI2019 travels Java Basics ( Bubble sort )Unity Scene loading asynchronously ( Implementation of loading interface )" Cephalosporin wine Say go and go "? DANGER ! Don't drink alcohol when taking these drugs 2021 year 1 Monthly programmer salary statistics , average 14915 element Huawei certification HCIA-AI artificial intelligence java Simple lottery algorithm , luck draw DemoNOI2019 travels