QT 编程,StandardDialog、 QFileDialog

目录

1、StandardDialog:

      1、 模态对话框:

       2、非模态对话框:

  2、QFileDialog: 文件对话框

3、QMessageBox: 消息框

 4、QInputDialog: 输入对话框

5、QErrorMessage: 错误对话框

6、QFontDialog: 字体对话框

7、QColorDialog: 颜色对话框

1、StandardDialog:

      1、 模态对话框:

              QDialog dialog(this);

              dialog.resize(300, 200);

              //当使用QDialog::exec()成员函数的时候,弹出的对话框是模态对话框,会阻止用户的输入,直到用户关闭它

              dialog.exec();

       2、非模态对话框:

              QDialog *dialog = new QDialog(this);

              //设置属性,当用户关闭该对话框的时候在删除整个对象

              dialog->setAttribute(Qt::WA_DeleteOnClose);

              dialog->resize(300, 200);

              //当使用QDialog::show()成员函数的时候,弹出的对话框是非模态对话框,不会阻止用户的输入

              dialog->show();

  2、QFileDialog: 文件对话框

           静态函数

              getOpenFileName();

              getOpenFileNames();

              getExistingDirectory();

           QString fileName = QFileDialog::getOpenFileName(this, "打开文件", ".", "文本文件 (*.h *.cpp *.txt)");

              QStringList fileNames = QFileDialog::getOpenFileNames(this, "打开文件", ".", "文本文件 (*.h *.cpp *.txt)");

3、QMessageBox: 消息框

           静态函数

              question();

              warning();

              information();

              abort();

              abortQt();

              QMessageBox msgBox;

              msgBox.setText("请确保您的数据准确.");

              msgBox.setInformativeText("确定要提交您的个人信息吗?");

              msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

              msgBox.setDefaultButton(QMessageBox::Yes);

              int ret = msgBox.exec();

              switch (ret)

              {

                     case QMessageBox::Yes:

                            this->close();

                            break;

                     default:

                            break;

              }

 4、QInputDialog: 输入对话框

              QInputDialog::getDouble

              QInputDialog::getText();

              QInputDialog::getInt();

              double num = QInputDialog::getDouble(this, "获得一个浮点数", "请输入一个浮点数:", 100, 0, 100, 5);             

5、QErrorMessage: 错误对话框

              QErrorMessage *errMsg = QErrorMessage::qtHandler();

              //errMsg->setAttribute(Qt::WA_DeleteOnClose);

              errMsg->showMessage("this is a system error");

              errMsg->showMessage("this is a array overflow error");

              errMsg->showMessage("this is a system error");

              errMsg->showMessage("this is a array overflow error");             

6、QFontDialog: 字体对话框

              QFontDialog::getFont();

                  bool isOk;

                     QFont font = QFontDialog::getFont(&isOk, this);

                     if (isOk)

                     {

                            te->setFont(font);

                     }

                     else

                     {

                            te->setFont(originalFont);

                     }             

7、QColorDialog: 颜色对话框

           QColorDialog::getColor();

           QColor color = QColorDialog::getColor();

你可能感兴趣的:(qt,开发语言)