当前位置:网站首页>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
边栏推荐
- Uniapp skills - dom display and hiding
- Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
- 金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
- php 迷宫游戏
- Qt学习22 布局管理器(一)
- Go: send the get request and parse the return JSON (go1.16.4)
- Thrift threadmanager and three monitors
- Rasp implementation of PHP
- pytorch 载入历史模型时更换gpu卡号,map_location设置
- Record 405 questions about bank callback post request
猜你喜欢
消息订阅与发布
Implementation of Muduo asynchronous logging
Unity embeddedbrowser browser plug-in event communication
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Spring cup eight school league
Flutter dynamic | fair 2.5.0 new version features
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
随机推荐
PHP maze game
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
记录关于银行回调post请求405 问题
php 迷宫游戏
MySQL data processing value addition, deletion and modification
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
Multi person collaborative data annotation based on Baidu brain easydata from scratch
Ocean CMS vulnerability - search php
Qt学习17 对话框及其类型
Golang — template
挡不住了,国产芯片再度突进,部分环节已进到4nm
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
顺序表(C语言实现)
Heap structure and heap sort heapify
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
How to use lxml to judge whether the website announcement is updated
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
JS continues to explore...