#include "dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent) { resize(260,80); glayout = new QGridLayout(this); labelmsg=new QLabel("自定义消息框"); msgButton=new QPushButton("测试操作"); labeldispmsg=new QLabel("未测试到状态"); glayout->addWidget(labelmsg,0,0); glayout->addWidget(msgButton,0,1); glayout->addWidget(labeldispmsg,1,0,1,1); connect(msgButton,SIGNAL(clicked()),this,SLOT(customMsg())); } Dialog::~Dialog() { } void Dialog::customMsg() { QMessageBox cMsgBox; cMsgBox.setWindowTitle("自定义窗口"); //添加按钮 QPushButton *yes=cMsgBox.addButton("Yes",QMessageBox::ActionRole); QPushButton *no=cMsgBox.addButton("NO",QMessageBox::ActionRole); //添加图标 cMsgBox.setIconPixmap(QPixmap("D:\\myProject\\QT\\qtwidget\\StepBarIcon.png")); cMsgBox.exec(); //判断用户点击按钮yes no if(cMsgBox.clickedButton()==yes){ labeldispmsg->setText("yes"); }else{ labeldispmsg->setText("no"); } }
标签:12,QT,自定义,Dialog,new,yes,labeldispmsg,cMsgBox From: https://www.cnblogs.com/baisedeyu/p/17887112.html