Qt学习之路(5):对话框传递数据|标准对话框QMessageBox
来源:互联网 发布:淘宝充值软件多钱 编辑:程序博客网 时间:2024/05/27 19:27
模态对话框的数据传递相对较为简单,只讨论非模态的对话框的数据传递。由于对话框关闭的时候会调用accept或者reject(),所以我们可以在里面进行处理.
自己定义一个带button(Ok,Cancel)的对话框,然后进行在accept(),reject()函数里进行对数据的输出.
void UserAgeDialog::accept()//在这里发送信号{ qDebug()<<"Dialog is accepted"; QDialog::accept();//调用基类的函数,将会发送信号}void UserAgeDialog::reject(){ qDebug()<<"Dialog is rejected"; QDialog::reject();}
===========================================
这是调用了QMessageBox(模态对话框)的几个static函数创建的一个question对话框,它很方便,但是并不灵活(只能添加一些按钮)。我们只能使用几种简单的形式.
void MainWindow::open(){ auto ret = QMessageBox::question(this,"Question","Are you Okay", QMessageBox::Yes|QMessageBox::No|QMessageBox::Save,QMessageBox::Yes); if(QMessageBox::Yes == ret) QMessageBox::information(this,"Hmm...","I'm glad to say it"); else if(QMessageBox::No == ret) QMessageBox::information(this,"Hmm...","I'm so sorry"); else QMessageBox::information(this,"Hmm...","all files have been saved");}
#
===========================================
如果我们想要制定QMessageBox的细节,那么就必须调用相应的API接口自己设置.
有几点需要注意,我们处理自定义的按钮时,需要使用clickedbutton()进行判断,这是因为exec()的返回值不会返回除了内置的一些按钮之外的值,对于我们自定义的按钮,它只会返回0.
void MainWindow::open(){ QMessageBox msgBox(QMessageBox::Information, "Question","The document has been modified"); msgBox.setInformativeText("Do you want to save all your changes?"); msgBox.setDetailedText(tr("Differences here..."));//添加详细信息,会自动添加一个按钮 msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Save);//设定默认按钮 QPushButton *okbtn=new QPushButton(QObject::tr("确定")); msgBox.addButton(okbtn,QMessageBox::AcceptRole);//添加自定义按钮(注意可以是中文) auto ret = msgBox.exec();//获得返回值 switch (ret) { case QMessageBox::Save: qDebug() << "Save document!"; break; case QMessageBox::Discard: qDebug() << "Discard changes!"; break; case QMessageBox::Cancel: qDebug() << "Close document!"; break; } if(msgBox.clickedButton()==okbtn)//处理自定义的按钮 qDebug()<<"Fucking";}
1 0
- Qt学习之路(5):对话框传递数据|标准对话框QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt学习之路(17): Qt标准对话框之QMessageBox
- Qt 学习之路 2(15):标准对话框 QMessageBox
- Qt 学习之路 2(15):标准对话框 QMessageBox
- Qt标准对话框之QMessageBox
- Qt标准对话框之QMessageBox
- Qt标准对话框之QMessageBox
- ChinaUnix中fastdfs论坛资料之FastDFS一个高效的分布式文件系统
- OKHttp使用简单介绍,实用教程
- XCode7 新特性 Bitcode
- HI3518视频画面偏色解决办法小记
- activemq的几种基本通信方式总结
- Qt学习之路(5):对话框传递数据|标准对话框QMessageBox
- linux配置yum
- MySQL 调优 —— Using filesort
- android 硬件加速
- 一键开关机电路
- WIN7 WIN8 下 DELPHI遍历系统声卡 修改系统MIC声音大小的办法!
- Print call frame
- [codeforces383C - Propagating tree] dfs序 +segment tree
- Mysql Replication同步总结