QT5笔记: 23. 标准对话框
文件对话框:
QString fileName = QFileDialog::getOpenFileName(this, "打开一个文件", path, "文本(*.txt);;图片文件(*.jpg *.png);;所有文件(*.*)");
QStringList fileNames = QFileDialog::getOpenFileNames(this, "打开多个文件", "文本(*.txt);;图片文件(*.jpg *.png);;所有文件(*.*)");
QString dir = QFileDialog::getExistingDirectory(this, "选择一个文件夹", path);
QString fileName = QFileDialog::getSaveFileName(this, "选择保存目录", path, "文本(*.txt);;所有文件(*.*)");
颜色对话框
QColor color = QColorDialog::getColor(defaultColor, this, "选择文本颜色");
字体对话框
QFont font = QFontDialog::getFont(&ok, this);
输入对话框
int number = QInputDialog::getInt(this, "输入数字", "请输入数字", size, -10, 1000, 2, &ok, Qt::WindowType::Tool);
double number = QInputDialog::getDouble(this, "输入数字", "请输入数字,可以为小数", 0, -10, 1000, 2, &ok, Qt::WindowType::Tool);
QString item = QInputDialog::getItem(this, "选择项", "选择今天星期几", items, 1, false, &ok, Qt::Tool);
QString text = QInputDialog::getText(this, "输入文本", "请输入写入内容", QLineEdit::Normal);//NoEcho 表示不做回显处理
标准消息框
QMessageBox::StandardButton btn = QMessageBox::question(this, "A Question Dialog", "yes? no?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No);//返回值为点击的按钮
QMessageBox::StandardButton info = QMessageBox::information(this, "A Information Dialog", "For Test", QMessageBox::Ok, QMessageBox::Ok);
QMessageBox::warning(this, "Warning", "Warning");
QMessageBox::critical(this, "Critical", "Warning");
QMessageBox::about(this, "About", "About");
QMessageBox::aboutQt(this, "About Qt");//这个是关于Qt的信息