C/C++ -- Gui编程 -- Qt库的使用 -- 标准对话框

时间:2023-03-08 15:48:06

-----mywidget.cpp-----

 #include "mywidget.h"
 #include "ui_mywidget.h"
 #include <QFileDialog>
 #include <QColorDialog>
 #include <QFontDialog>
 #include <QInputDialog>
 #include <QMessageBox>
 #include <QProgressDialog>
 #include <QErrorMessage>
 #include <QDebug>

 MyWidget::MyWidget(QWidget *parent) :
     QWidget(parent),
     ui(new Ui::MyWidget)
 {
     ui->setupUi(this);
 }

 MyWidget::~MyWidget()
 {
     delete ui;
 }

 void MyWidget::on_pushButton_clicked()
 {
     QStringList filenames = \
             QFileDialog::getOpenFileNames(\
                 this, "文件对话框", "F:",\
                 "图片(*png);;音乐(*mp3 *wma)");
     qDebug()<<"FileNames"<<filenames<<endl;
 }

 void MyWidget::on_pushButton_3_clicked()
 {
     QColor color = QColorDialog::getColor(Qt::red, this, "颜色选择", \
                                           QColorDialog::ShowAlphaChannel);
     qDebug()<<color<<endl;
 }

 void MyWidget::on_pushButton_2_clicked()
 {
     bool ok;
     QFont font = QFontDialog::getFont(&ok, this);
     if(not ok)
         qDebug()<<"没有选择字体"<<endl;
     else
         qDebug()<<"字体:"<<font<<endl;
 }

 void MyWidget::on_pushButton_4_clicked()
 {
     bool ok;
     QString string = QInputDialog::getText(this, "字符串", "请输入字符串",QLineEdit::Normal, "admin", &ok);
     if(ok) qDebug()<<"输入了字符串"<<string<<endl;
     , -, , , &ok);
     if(ok) qDebug()<<"输入了整数"<<value<<endl;
     , &ok);
     if(ok) qDebug()<<"输入了浮点数"<<d<<endl;
     QStringList items;
     items<<"条目1"<<"条目2";
     QString item = QInputDialog::getItem(, true, &ok);
     if(ok)qDebug()<<"选择了条目"<<item;
 }

 void MyWidget::on_pushButton_5_clicked()
 {
     int ret = QMessageBox::question(this, "列位看官", "你道此书从何而来?", QMessageBox::Yes, QMessageBox::No);
     if(ret == QMessageBox::Yes)
         qDebug()<<"说起根由虽近荒唐,细按则深有趣味"<<endl;
     ret = QMessageBox::information(this, "一场幽梦同谁近", "千古情人独我痴", QMessageBox::Ok);
     if(ret == QMessageBox::Ok)
         qDebug()<<"谋事在人,成事在天"<<endl;
     ret = QMessageBox::warning(this,"《四部丛刊》", "《经进东坡文集事略》 ", QMessageBox::Abort);
     if(ret == QMessageBox::Abort)
         qDebug()<<"天道不言而品物亨、岁功成"<<endl;
     ret = QMessageBox::critical(this, "致虚极,守静笃", "万物并作,吾以观复", QMessageBox::YesAll);
     if(ret == QMessageBox::YesAll)
         qDebug()<<"明月皎皎照我床,星汉西流夜未央"<<endl;
     QMessageBox::about(this, "不出户,知天下;不窥牖,见天道。", \
                        "其出弥远,其知弥少。是以圣人不行而知,不见而明,不为而成");
     QMessageBox::aboutQt(this);
 }

 void MyWidget::on_pushButton_6_clicked()
 {
     QProgressDialog dlg(, , this);
     dlg.setWindowTitle("RECUVA");
     dlg.setWindowModality(Qt::WindowModal);
     dlg.show();
     ; i<; i++)
     {
         dlg.setValue(i);
         QCoreApplication::processEvents();
         if(dlg.wasCanceled())
             break;
     }
     dlg.setValue();
     qDebug()<<"恢复结束"<<endl;
 }

 void MyWidget::on_pushButton_7_clicked()
 {
     QErrorMessage *dlg = new QErrorMessage(this);
     dlg->setWindowTitle("这不是你的错");
     dlg->showMessage("卡莱尔轻声地安慰我说");
 }

 QWizardPage* MyWidget::createPage1()
 {
     QWizardPage * page = new QWizardPage;
     page->setTitle("欢迎进入Windows卸载向导");
     return page;
 }
 QWizardPage* MyWidget::createPage2()
 {
     QWizardPage * page = new QWizardPage;
     page->setTitle("你真的要卸载吗?");
     return page;
 }
 QWizardPage* MyWidget::createPage3()
 {
     QWizardPage * page = new QWizardPage;
     page->setTitle("卸载已完成");
     return page;
 }

 void MyWidget::on_pushButton_8_clicked()
 {
     QWizard wizard(this);
     wizard.setWindowTitle("Win7卸载向导");
     wizard.addPage(createPage1());
     wizard.addPage(createPage2());
     wizard.addPage(createPage3());
     wizard.exec();
 }

C/C++ -- Gui编程 -- Qt库的使用 -- 标准对话框

C/C++ -- Gui编程 -- Qt库的使用 -- 标准对话框