Reputation: 2256
I am trying to create a program that allows the user to open a pre-existing file and save current files. For opening a file I am using:
dlg = QFileDialog(self, "Open", "", "Yaml(*.yaml)")
filenames = QStringList()
if dlg.exec_():
filenames = dlg.selectedFiles()
FILE_NAME = str(QFileInfo(filenames[0]).baseName())
For saving files I am using:
_fileName = QFileDialog().getSaveFileName(self, "Save", "./", "Yaml(*.yaml)")
FILE_NAME = str(QFileInfo(_fileName).baseName())
However, graphically I am noticing differences between the open and save methods.
I know I am not using QFileDialog.getOpenFileName(...) This is because QFileDialog.getSaveFileName(...) outputs a bunch of errors when loading the GUI.
Failed enumerating UDisks2 objects: "org.freedesktop.DBus.Error.Disconnected"
"Not connected to D-Bus server"
Is there anyway that I can use QFileDialog to save files? Note that QFileDialog() by default has an "Open" button, is there anyway to change this to "Save"
Upvotes: 0
Views: 1678
Reputation: 2256
I found a solution.
QFileDialog has a method called setAcceptMode(QFileDialog.AcceptMode) which allows you to change between Open and Save. http://pyqt.sourceforge.net/Docs/PyQt4/qfiledialog.html#setAcceptMode
Usage for open:
QFileDialog.setAcceptMode(QtGui.QFileDialog.AcceptOpen)
Usage for Save:
QFileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave)
Upvotes: 0