Qt提供了一些可以复用的对话框类型,这些对话框类型全部继承与QDialo类。

Qt中标准对话框遵循相同的使用方法:
//定义对话框对象
DialogType dlg(this);
//设置对话框属性
dlg.setPrpertyXXX(value);
if(dlg.exec() == DialogType::value)
{
//获取对话框数据
Type V = dlg.getDialogValue();
//处理对话框数据
//....
}
Qt消息对话框:QMessageBox
QMessageBox 中的实用函数。
void about ( QWidget * parent, const QString & title, const QString & text ) void aboutQt ( QWidget * parent, const QString & title = QString() ) StandardButton critical ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ) StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ) StandardButton question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ) StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
测试代码:
QMessageBox Mes(this);
/*消息提示对话框*/
// if( Mes.information(this,"MessageBox","this is MessageBox!",QMessageBox::Ok,QMessageBox::Cancel,QMessageBox::YesAll)
// == QMessageBox::Ok)
// {
// qDebug()<<"QMessageBox::Ok";
// }
/*警告提示对话框*/
// if( Mes.warning(this,"MessageBox","this is MessageBox!",QMessageBox::Ok,QMessageBox::Cancel,QMessageBox::YesAll)
// == QMessageBox::Ok)
// {
// qDebug()<<"QMessageBox::Ok";
// }
/*问题提示对话框*/
// if( Mes.question(this,"MessageBox","this is MessageBox!",QMessageBox::Ok,QMessageBox::Cancel,QMessageBox::YesAll)
// == QMessageBox::Ok)
// {
// qDebug()<<"QMessageBox::Ok";
// }
/*关键提示对话框*/
// if( Mes.critical(this,"MessageBox","this is MessageBox!",QMessageBox::Ok,QMessageBox::Cancel,QMessageBox::YesAll)
// == QMessageBox::Ok)
// {
// qDebug()<<"QMessageBox::Ok";
// }
Mes.about(this,"MessageBox","this is MessageBox!");
// Mes.setWindowTitle("MessageBox");//设置标题
// Mes.setText("this is MessageBox~");//设置提示内容
// Mes.setIcon(QMessageBox::Warning);
// Mes.setStandardButtons(QMessageBox::Ok|QMessageBox::Cancel|QMessageBox::YesAll);
// if(Mes.exec() == QMessageBox::Ok)
// {
// qDebug()<<"QMessageBox::Ok";
// }
qDebug()<<"Messege_BtnClicked";
Qt文件对话框:QFileDialog
Open Mode
——应用程序需要用户打开一个外部文件
QFileDialog fl;
fl.setAcceptMode(QFileDialog::AcceptOpen);//设置为Open模式
QStringList setFs ;
setFs <<"Text(*.txt)"<<"All(*.*)";
fl.setFilters(setFs);
/*QFileDialog::ExistingFile 打开单个
QFileDialog::ExistingFiles 打开多个文件
*/
fl.setFileMode(QFileDialog::ExistingFile);
if(fl.exec() == QFileDialog::Accepted)
{
QStringList fs = fl.selectedFiles();//获取文件路径 文件名
for(int i=0;i<fs.count();i++)
{
qDebug()<<fs[i];
}
}
qDebug()<<"FileDialog_BtnClicked";
Save Mode
——应用程序需要将当前内容存储到用户指定的目录中去
来源:https://www.cnblogs.com/hjxzjp/p/12285988.html