1.消息对话框
//问题对话框
int ret1 = QMessageBox::question(
this,QString("问题对话框"),QString("first?"),QMessageBox::Yes,QMessageBox::No);
if (ret1 == QMessageBox::Yes) {
qDebug() << QString("问题!");
}
//提示对话框
int ret2 = QMessageBox::information(
this,QString("问题对话框"),QString("这是Qt书籍!"),QMessageBox::Ok);
if (ret2 == QMessageBox::Ok) {
qDebug() << QString("提示!");
}
//警告对话框
int ret3= QMessageBox::warning(
this,QString("警告对话框"),QString("不能提前结束!"),QMessageBox::Abort);
if (ret3 == QMessageBox::Abort) {
qDebug() << QString("警告!");
}
//错误对话框
int ret4 = QMessageBox::critical(
this,QString("严重错误对话框"),QString("发现一个严重错误!,现在要关闭所有文件!"),QMessageBox::YesAll);
if (ret4 == QMessageBox::YesAll) {
qDebug() << QString("错误!");
}
//关于对话框
QMessageBox::about(this,QString("关于对话框"),QString("Qt及QtCreator的普及工作!"));
2.进度对话框
QProgressDialog progressDlg(QString("文件复制进度"),QString("取消"),0,5000,this);
progressDlg.setWindowTitle("进度对话框"); //设置窗口标题
progressDlg.setWindowModality(Qt::WindowModal);//将对话框设置为模态
progressDlg.show();
for (int i=0; i<50000; i++) { //演示复制进度
progressDlg.setValue(i); //进度条的值
QCoreApplication::processEvents(); //避免界面冻结
if (progressDlg.wasCanceled()) break; //按下取消按钮就中断
}
progressDlg.setValue(50000); //保证显示的是100%
qDebug() << QString("复制结束");
3.错误信息对话框
QErrorMessage * errDlg = new QErrorMessage(this);
errDlg->setWindowTitle(QString("错误信息对话框"));
errDlg->showMessage(QString("这里是错误信息"));
4.向导对话框
- 添加向导页
QWizardPage *createPage1();
QWizardPage *createPage2();
QWizardPage *createPage3();
生成向导
QWizard wizard(this);
wizard.setWindowTitle(QString("向导对话框"));
wizard.addPage(createPage1());
wizard.addPage(createPage2());
wizard.addPage(createPage3());
wizard.exec();