当前位置:网站首页>QT learning 19 standard dialog box in QT (top)
QT learning 19 standard dialog box in QT (top)
2022-07-03 13:58:00 【A little black sauce】
Qt Study 19 Qt Standard dialog boxes in ( On )
Standard dialog box
- Qt Provides some for developers Reusable Dialog type
- Qt Reusable dialog provided The whole country does not inherit from QDialog class
- Qt Standard dialog boxes in Follow the same usage
// Define dialog objects
DialogType dlg(this);
// Set dialog properties
dlg.setPropertyXXX(value);
if(dlg.exec() == DialogType::Value) {
// Get dialog data
Type v = dlg.getDialogValue();
// Process dialog data
// ....
}
Message dialog
- Message dialog It's in the application The most common interface element
- The message dialog box is mainly used for :
- For the user Prompt important information
- Force users Make operation selection
- How to use the message dialog
// Construct message dialog object
QMessageBox msg(this);
// Set the relevant properties of the message dialog
msg.setWindowTitle("Message Title");
msg.setText("This is message content!");
msg.setIcon(QMessageBox::Information);
msg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
if (msg.exec() == QMessageBox::Ok) {
qDebug() << "Ok button is clicked!";
}
File dialog
File dialog boxes are often used in the following situations
Open Mode
- In the application You need to open an external file
Save Mode
- In the application The current content needs to be stored in the external file specified by the user
How to use the file dialog
QFileDialog fd(this);
//
fd.setAcceptMode(QFileDialog::AcceptOpen);
fd.setFileMode(QFileDialog::ExistingFile);
if (fd.exec() == QFileDialog::Accepted) {
QStringList fs = fd.selectedFiles();
}
file type filter
In the file dialog box, you can Define filters through file suffixes
Filter definition rules :
Display name ( *. suffix 1 *. suffix 2 … *. suffix N )
example :“Image ( *.png *.xpm *.jpg )”
“Text ( *.txt )”
“All ( *.* )”
QFileDialog Using functions in
- QFileDialog::getOpenFileName
- QFileDialog::getOpenFileNames
- QFileDialog::getSaveFileName
Code experiments
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
class Widget : public QWidget
{
Q_OBJECT
private:
QPushButton SimpleMsgBtn;
QPushButton CustomMsgBtn;
QPushButton OpenFileBtn;
QPushButton SaveFileBtn;
private slots:
void SimpleMsgBtn_Clicked();
void CustomMsgBtn_Clicked();
void OpenFileBtn_Clicked();
void SaveFileBtn_Clicked();
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QDebug>
#include <QMessageBox>
#include <QFileDialog>
Widget::Widget(QWidget *parent) : QWidget(parent),
SimpleMsgBtn(this), CustomMsgBtn(this), OpenFileBtn(this), SaveFileBtn(this)
{
SimpleMsgBtn.setText("Simple Message Dialog");
SimpleMsgBtn.move(20, 20);
SimpleMsgBtn.resize(160, 30);
CustomMsgBtn.setText("Custom Message Dialog");
CustomMsgBtn.move(20, 70);
CustomMsgBtn.resize(160, 30);
OpenFileBtn.setText("Open File Dialog");
OpenFileBtn.move(20, 120);
OpenFileBtn.resize(160, 30);
SaveFileBtn.setText("Save File Dialog");
SaveFileBtn.move(20, 170);
SaveFileBtn.resize(160, 30);
resize(200, 220);
connect(&SimpleMsgBtn, SIGNAL(clicked()), this, SLOT(SimpleMsgBtn_Clicked()));
connect(&CustomMsgBtn, SIGNAL(clicked()), this, SLOT(CustomMsgBtn_Clicked()));
connect(&OpenFileBtn, SIGNAL(clicked()), this, SLOT(OpenFileBtn_Clicked()));
connect(&SaveFileBtn, SIGNAL(clicked()), this, SLOT(SaveFileBtn_Clicked()));
}
Widget::~Widget()
{
}
void Widget::SimpleMsgBtn_Clicked()
{
QMessageBox msg(this);
msg.setText("This is a message dialog!");
msg.exec();
}
void Widget::CustomMsgBtn_Clicked()
{
QMessageBox msg(this);
msg.setWindowTitle("Window Title");
msg.setText("This is a detail message dialog!");
msg.setIcon(QMessageBox::Information);
msg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel | QMessageBox::YesToAll);
if (msg.exec() == QMessageBox::Ok) {
qDebug() << "Ok button is clicked!";
}
// Simple usage
QMessageBox::information(this, "Window Title", "This is a detail message dialog!", QMessageBox::Ok|QMessageBox::Cancel|QMessageBox::YesToAll);
QMessageBox::question(this, "Question", "This is a question dialog!", QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
QMessageBox::warning(this, "Warning", "This is a warning dialog", QMessageBox::Ok);
QMessageBox::critical(this, "Warning", "This is a warning dialog!", QMessageBox::Ok);
QMessageBox::about(this, "About", "This is a about dialog!");
}
void Widget::OpenFileBtn_Clicked()
{
QFileDialog dlg(this);
dlg.setAcceptMode(QFileDialog::AcceptOpen);
dlg.setFileMode(QFileDialog::ExistingFiles);
if (dlg.exec() == QFileDialog::Accepted) {
QStringList fs = dlg.selectedFiles();
for (int i = 0; i < fs.count(); i++) {
qDebug() << fs[i];
}
}
// Simple usage
QFileDialog::getOpenFileName(this, tr("Open File"), "./", tr("Images (*.png *.xpm *.jpg)"));
QFileDialog::getOpenFileNames(this, "Select one or more files to open", "./", "Images (*.png *.xpm *.jpg)");
}
void Widget::SaveFileBtn_Clicked()
{
QFileDialog dlg(this);
dlg.setAcceptMode(QFileDialog::AcceptSave);
if (dlg.exec() == QFileDialog::Accepted) {
QStringList fs = dlg.selectedFiles();
for (int i = 0; i < fs.count(); i++) {
qDebug() << fs[i];
}
}
// Simple usage
QFileDialog::getSaveFileName(this, tr("Save File"), "./untitled.png", tr("Images (*.png *.xpm *.jpg)"));
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
Summary
- Qt More than one Reusable Dialog type
- Inherited from QDialog type
- follow identical Usage mode
- QMessageBox Used to prompt important program information
- QFileDialog Used to get the file path in the system
边栏推荐
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- Failure of vector insertion element iterator in STL
- Unity Render Streaming通过Js与Unity自定义通讯
- 树的深入和广度优先遍历(不考虑二叉树)
- Similarities and differences of sessionstorage, localstorage and cookies
- jvm-对象生命周期
- Richview trvstyle liststyle list style (bullet number)
- IBEM 数学公式检测数据集
- Installation impression notes
- MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
猜你喜欢
Uniapp tips - scrolling components
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
How to use lxml to judge whether the website announcement is updated
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
如何使用lxml判断网站公告是否更新
jvm-类加载
信创产业现状、分析与预测
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Ocean CMS vulnerability - search php
随机推荐
php 迷宫游戏
Uniapp tips - scrolling components
mysql中的字段问题
Analysis of the characteristics of page owner
[acnoi2022] guess numbers
Golang — template
掌握Cypress命令行选项,是真正掌握Cypress的基础
[技术发展-24]:现有物联网通信技术特点
Windos creates Cordova prompt because running scripts is prohibited on this system
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
Record 405 questions about bank callback post request
Uniapp tips - set background music
Qt学习21 Qt 中的标准对话框(下)
Qt学习18 登录对话框实例分析
How to use lxml to judge whether the website announcement is updated
[how to earn a million passive income]
[ACNOI2022]猜数
Universal dividend source code, supports the dividend of any B on the BSC
Conversion function and explicit