Qfiledialog Save Open dialog box has two styles: Provide local dialog box on Windows and MacOS X platform QT Self-Painted dialog box

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.