11、QMessageBox(消息对话框)
#include "dialog.h" #include "ui_dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); resize(320,150); glayout = new QGridLayout(this); dispLabel = new QLabel("请选择标签"); questionButton= new QPushButton("Question"); informationButton= new QPushButton("Information"); warningButton= new QPushButton("Warning"); criticalButton= new QPushButton("Critical"); aboutButton= new QPushButton("About"); aboutqtButton= new QPushButton("AboutQt"); glayout->addWidget(dispLabel,0,0 ); glayout->addWidget(questionButton,1,0); glayout->addWidget(informationButton,1,1); glayout->addWidget(warningButton,2,0); glayout->addWidget(criticalButton,2,1); glayout->addWidget(aboutButton,3,0); glayout->addWidget(aboutqtButton,3,1); connect(questionButton,SIGNAL(clicked()),this,SLOT(displayQuestionMsg())); connect(informationButton,SIGNAL(clicked()),this,SLOT(displayInformationMsg())); connect(warningButton,SIGNAL(clicked()),this,SLOT(displayWarningMsg())); connect(criticalButton,SIGNAL(clicked(bool)),this,SLOT(displayCriticalMsg())); connect(aboutButton,SIGNAL(clicked(bool)),this,SLOT(displayAboutMsg())); connect(aboutqtButton,SIGNAL(clicked(bool)),this,SLOT(displayAboutQtMsg())); } Dialog::~Dialog() { delete ui; } void Dialog::displayQuestionMsg() { dispLabel->setText("Question"); switch(QMessageBox::question(this,"Question消息框","你是否想退出应用程序", QMessageBox::Ok|QMessageBox::Cancel )) { case QMessageBox::Ok: dispLabel->setText("Question->Ok"); break; case QMessageBox::Cancel: dispLabel->setText("Question->cancel"); break; default: break; } return; } void Dialog::displayInformationMsg() { dispLabel->setText("Infomation"); QMessageBox::information(this,"Infomation消息框","Infomation测试"); } void Dialog::displayWarningMsg() { dispLabel->setText("warning"); switch (QMessageBox::warning(this,"Warning消息框","Warning测试",QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save)) { case QMessageBox::Save: dispLabel->setText("warning->save"); break; case QMessageBox::Discard: dispLabel->setText("warning->Discard"); break; case QMessageBox::Cancel: dispLabel->setText("warning->Cancel"); break; default: break; } } void Dialog::displayCriticalMsg() { dispLabel->setText("cirtical"); QMessageBox::critical(this,"cirtical消息框","cirtical测试"); } void Dialog::displayAboutMsg() { dispLabel->setText("About"); QMessageBox::about(this,"about消息框","about测试"); } void Dialog::displayAboutQtMsg() { dispLabel->setText("AboutQT"); QMessageBox::aboutQt(this,"about QT消息框测试"); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端