PDA

View Full Version : Non-native, customized QFileDialog to have Save button instead of Open?



falconium
10th May 2011, 23:54
Hi,

Is there a way to have QFileDialog show Save button instead of Open if it is customized?
I know I could use QFileDialog::getSaveFileName, but in this case I don't know how to add QUrls to sidebar, etc.

Thanks!


QList<QUrl> sidebarURLs;
sidebarURLs << QUrl::fromLocalFile(lastPath);
sidebarURLs << QUrl::fromLocalFile(QDesktopServices::storageLocat ion(QDesktopServices::DocumentsLocation));
sidebarURLs << QUrl::fromLocalFile(QDesktopServices::storageLocat ion(QDesktopServices::DesktopLocation));

QFileDialog fileOpenDialog(this);
fileOpenDialog.setWindowTitle(tr("Save chart file"));
fileOpenDialog.setDirectory(lastPath);
fileOpenDialog.setViewMode(QFileDialog::Detail);
fileOpenDialog.setSidebarUrls(sidebarURLs);
fileOpenDialog.setFileMode(QFileDialog::AnyFile);
fileOpenDialog.setOption(QFileDialog::DontUseNativ eDialog);
fileOpenDialog.setNameFilter(tr("Chart data (*.chart)"));

rsilva
10th May 2011, 23:59
fileOpenDialog.setAcceptMode(QFileDialog::AcceptSa ve);

falconium
11th May 2011, 00:03
Thanks! I have also just found it from qfiledialog.cpp source code: 02280 dlg->setAcceptMode(AcceptSave);
:rolleyes: