QMessageBox
Posted data1213
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QMessageBox相关的知识,希望对你有一定的参考价值。
设置标准按钮:帮助文档代码
1 QMessageBox msgBox; 2 msgBox.setText("The document has been modified."); 3 msgBox.setInformativeText("Do you want to save your changes?"); 4 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); 5 msgBox.setDefaultButton(QMessageBox::Save); 6 int ret = msgBox.exec();
显式效果:
The exec() slot returns the StandardButtons value of the button that was clicked.
1 switch (ret) { 2 case QMessageBox::Save: 3 // Save was clicked 4 break; 5 case QMessageBox::Discard: 6 // Don‘t Save was clicked 7 break; 8 case QMessageBox::Cancel: 9 // Cancel was clicked 10 break; 11 default: 12 // should never be reached 13 break; 14 }
可选标准按钮:
自定义按钮:
选用:
1 QPushButton * addButton(const QString &text, QMessageBox::ButtonRole role)
role的可选值:
1 void AddStudents::my_add_students_info_ok_slots(){ 2 3 //获取lineEdit控件的输入信息 4 QString name = this->ui->lineedit_name->text(); 5 QString id = this->ui->lineedit_id->text(); 6 7 //在QMessageBox中自定义按钮 8 QMessageBox msgBox; 9 msgBox.addButton("确定",QMessageBox::AcceptRole); 10 QPushButton * reback_on_cancel = msgBox.addButton("取消",QMessageBox::RejectRole); 11 //设置默认选中是取消按钮 12 msgBox.setDefaultButton(reback_on_cancel); 13 //显式lineEdit控件的输入信息 14 msgBox.setText(name+‘\\n‘+id); 15 int ret = msgBox.exec(); 16 }
以上是关于QMessageBox的主要内容,如果未能解决你的问题,请参考以下文章
Python——pyqt5——消息框(QMessageBox)