[PyQt] User selected filter in QFileDialog

Phil Thompson phil at riverbankcomputing.com
Tue Jun 30 16:06:17 BST 2009


On Tue, 30 Jun 2009 05:14:27 -0700 (PDT), barmanoo
<olivier.friard at gmail.com> wrote:
> Hi,
> 
> 
> I have a problem with QFileDialog to check what filter the user has
> selected.
> 
> My code is:
> 
> 
> 
> fd=QFileDialog(self)
> 
> projectFileName=fd.getSaveFileName(self,'Save the current
> project','','project type 1 (*.project1);;project type 2
(*.project2);;All
> files (*)','project type 1 (*.project1)')
> 
> selected_filter=str(fd.selectedNameFilter())
> 
> 
> Unfortunatly whatever filter the user had selected the selected_user
> variable always contains "All Files (*)". There is no way to know what
> filter was used by the user.
> 
> 
> Any idea?

getSaveFileName() is a static method that creates its own dialog. In other
words the dialog the user is using isn't the same one you have created.

selected_filter = QString()
projectFileName = QFileDialog.getSaveFileName(self, 'Save the current
project', '',
        'your;;filters', selected_filter)

selected_filter will be updated with the selected filter (a horribly
unpythonic API).

Phil


More information about the PyQt mailing list