Applications dialog: My three Qt study plan

A dialog species

(A) class is the base class QDialog dialog window.
1, a dialog window is a top-level window, and is mainly used for short-term assignments and user of
a simple exchange between.
2, Qdialogs can provide a return value, and may have a default button.
3. Note: QDialog QT other classes differ in the use of the parent member.
A dialog box is usually a top part, but if it has a parent component, its default location is centered on the parent part, and the parent and units share the taskbar.

(B) the type of
modal dialog : that is, before it has not been closed, a user application can not be the same
for the other windows of the interactive program, until the dialog box is closed. Then often is needed
dialog return value of the following operations confirmation window. For example: Select "yes" or "no."
Modeless dialog boxes : when opened, the user can select and interact with the dialog box,
can choose to interact with other windows applications. After the pop-up window, the call that is
engraved returned, proceed to the next operation. For example, the Find dialog box.

Second, the dialog is displayed

Modal dialog set :
Mode 1:

QDialog dialog(this); 
dialog.exec (); 

Second way:

QDialog *dialog = new QDialog(this);
dialog->setModal (true); ;
dialog->show (); 

Provided modeless dialog boxes :

QDialog g *dialog = new QDialog(this); ;
dialog->show (); 

Third, the code demonstrates various dialogs

Create a project and ui layout:
Here Insert Picture Description
Here Insert Picture Description

Open File dialog box

Add header

#include <QFileDialog>

Go trough Code

void fileDialog::on_pushButton_clicked()//打开文件
{
    QString filename = QFileDialog::getOpenFileName(this,"打开文件","c:/","*.exe *.dll");//1.窗口2.名字第三个打开目录4.过滤器显示哪些文件
    qDebug()<<"open file:"<< filename;
}

result:
Here Insert Picture Description
Here Insert Picture Description

Get the text

Add header

#include <QDebug>
#include <QInputDialog>

Go trough Code

void fileDialog::on_pushButton_2_clicked()//打开文本框
{
    QString text = QInputDialog::getText(this,"输入文本","输入用户名",QLineEdit::Normal,"张三");
     qDebug()<<"文本为:"<< text;
}

Get a Digital
go trough the code:

void fileDialog::on_pushButton_2_clicked()//打开文本框
{
     int num = QInputDialog::getInt(this,"输入数字","输入0-100",0,0,100,10);//0到100,10个增长
     qDebug()<<"数字为:"<<num;
}

result:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Released three original articles · won praise 0 · Views 21

Guess you like

Origin blog.csdn.net/weixin_42626741/article/details/104411107