I would like to add a filter to the following code in order to select only the “CSV files”, but I did not succeed:
def filePath(title): qfd = QFileDialog() path = "D:\ennine\SIG HTB\BGN" f = QFileDialog.getOpenFileName(qfd, title, path) return f
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
According to the documentation you can add filter in the definition of your class:
QString QFileDialog.getOpenFileName (QWidget parent = None, QString caption = QString(), QString directory = QString(), QString filter = QString(), Options options = 0)
So with your code it should looks like :
def filePath(title): qfd = QFileDialog() path = "D:\ennine\SIG HTB\BGN" filter = "csv(*.csv)" f = QFileDialog.getOpenFileName(qfd, title, path, filter) return f
You can also add other filter. You need to separate them with a double ;; like so :
"Images (*.png *.xpm .jpg);;Text files (.txt);;XML files (*.xml)"
dialog = QtGui.QFileDialog() fname = dialog.getOpenFileName(None, "Window name", "", "CSV files (*.csv)")
Will do the job.
Just pass None as 1st agrument.