1. Open the dialog box two styles
(1) Local style
Qfiledialog *filedialog =NewQfiledialog ( This);
Filedialog->setwindowtitle (TR ("Open Image"));
Filedialog->setdirectory (".");
Filedialog->setfilter (TR ("Image Files (*.jpg *.png)"));
if(filedialog->exec () = = qdialog::accepted) {
QString path = filedialog->selectedfiles () [0];
Qmessagebox::information (NULL, TR ("Path"), TR ("you selected") + path);
}Else{
Qmessagebox::information (NULL, TR ("Path"), TR ("You didn ' t select any files."));
}
(2) QT style
QString Path = Qfiledialog::getopenfilename ( This, TR ("Open Image"),".", TR ("Image Files (*.jpg *.png)"));
if(path.length () = = 0) {
Qmessagebox::information (NULL, TR ("Path"), TR ("You didn ' t select any files."));
}Else{
Qmessagebox::information (NULL, TR ("Path"), TR ("you selected") + path);
}
Although the two types of writing are not very different, the pop-up dialog style is not the same. The GetOpenFileName () function provides a local dialog box on the Windows and MacOS X platforms, and Qfiledialog always provides a dialog box that QT draws itself (remember that the QT component is similar to swing and is drawn by itself, Instead of invoking the System Resource API).
2. Save dialog box style
(1) QT style
Qfiledialog FileDialog;
Filedialog.setacceptmode (Qfiledialog::acceptsave);//Set File dialog box for Save mode
Filedialog.setfilemode (qfiledialog::anyfile);///The Settings file dialog box pops up with any file, whether it's a folder or a file
Filedialog.setviewmode (qfiledialog::D etail);//file displayed in detail, showing file size, date, etc.
Filedialog.setwindowtitle ("Export geological stratification");
Filedialog.setdirectory (:: Getprojectfolder ());
Filedialog.setfilter ("Geos Files (*.geos)");
if (filedialog.exec () = = qdialog::accepted)
{
QString strFilePath = Filedialog.selectedfiles () [0];//Gets the file name entered by the user
QString strFileName = strFilePath + ". GeoS";
Cobjectarchive ar (Strfilename,estore);
cgeologicalstratificationroot* proot = dynamic_cast<cgeologicalstratificationroot*> (GetProject () Getgeologicalstratificationroot (true));
if (proot)
{
BOOL bsuccessful = proot->serialize (AR);
if (bsuccessful) qmessagebox::information (NULL, "hint", "Export succeeded!") ", Qmessagebox::ok);
else Qmessagebox::information (NULL, "Prompt", "Export failed!") ", Qmessagebox::ok);
}
}
(2) Local style
QString strFilePath = Qfiledialog::getsavefilename (NULL, "Save well log Project",:: Getprojectfolder (),
"Well log project file (*.geos)");
if (Strfilepath.isempty ()) return;
Save Project
Cobjectarchive ar (Strfilepath,estore);
cgeologicalstratificationroot* proot = dynamic_cast<cgeologicalstratificationroot*> (GetProject () Getgeologicalstratificationroot (true));
if (proot)
{
Proot->serialize (AR);
}
Note The Save dialog: the difference between the obtained strFilePath: the strname with the suffix geos obtained by getsavefilename (), Filedialog.selectedfiles () [0] obtained by strname without the suffix name
Note Open dialog: The difference between the strFilePath obtained: strname with suffix filedialog.selectedfiles () [0]
Qfiledialog Save Open dialog box has two styles: Provide local dialog box on Windows and MacOS X platform QT Self-Painted dialog box