QT five kinds of standard dialog box use method, and the realization effect, one of them — file dialog

Time:2020-9-5

QT five kinds of standard dialog box use method, and the realization effect, one of them — file dialog

There are three static functions in common file dialog box

Function name describe
QFileDialog::getOpenFileName Open a single file
QFileDialog::getOpenFileNames Open multiple files
QFileDialog::getSaveFileName Save the file
  • The first functionQFileDialog::getOpenFileNameFinally, a single file selection dialog box will pop up, as shown in the following figure:

How to use it

  • Parameters:

  • First parameter: specifies a parent pointer
  • The second parameter: set the title of the open file dialog box
  • The third parameter: Specifies the default path when opening the file dialog box
  • The fourth parameter: the filter condition when selecting a file. It is used when there are multiple filter conditions;;separate
  • Generally, the first four parameters are enough, and the latter two parameters have default parameters, which can not be specified
  • Return value:QStringType to return the path of the selected file with the file name
//Single file selection dialog box
QString filePath = QFileDialog::getOpenFileName(this,
					Qstringliteral ("open file"),
					"D:/Project/QstandardDialog/QStandardDialog",
					Qstringliteral ("header file (. H);; source file (. CPP)));
  • The second functionQFileDialog::getOpenFileNamesFinally, a multi file selection dialog box will pop up, as shown in the following figure:

How to use it

  • The parameters are the same as the single file dialog box
  • Return value:QStringListType to return multiple file paths with file names
//Multi file selection dialog box
QStringList filePath =QFileDialog::getOpenFileNames(this,
						 Qstringliteral ("open file"),
						"D:/Project/QstandardDialog/QStandardDialog",
						 Qstringliteral ("header file (. H);; source file (. CPP)));
  • The third functionQFileDialog::getSaveFileNameFinally, a multi file selection dialog box will pop up, as shown in the following figure:

How to use it

  • The parameters are the same as the single file dialog box
  • Return value:QStringType to return a file path with a file name
//Select file save path dialog box
    QString savePath = QFileDialog::getSaveFileName(this,
    				Qstringliteral ("storage file"),
    				"C:/Users/shish/Documents/",
    				QStringLiteral("image(*.png *.jpg);;text(*.txt)"));
  • Project code, extraction code: mhtg

Next: how to use 5 kinds of QT standard dialog boxes and their implementation effects, Part 2: qcolordialog

Recommended Today

Layout of angular material (2): layout container

Layout container Layout and container Using thelayoutDirective to specify the layout direction for its child elements: arrange horizontally(layout=”row”)Or vertically(layout=”column”)。 Note that if thelayoutInstruction has no value, thenrowIs the default layout direction. row: items arranged horizontally.max-height = 100%andmax-widthIs the width of the item in the container. column: items arranged vertically.max-width = 100%andmax-heightIs the height of the […]