[PyKDE] Re: QFileDialog.getOpenFileName with multiple filters
Alexander Borghgraef
alexander.borghgraef.rma at gmail.com
Fri Apr 21 13:09:01 BST 2006
On 4/21/06, Alexander Borghgraef <alexander.borghgraef.rma at gmail.com> wrote:
>
> Hi all,
>
> I'm trying to read in files in my PyQt app, so naturally I'm using
> QFileDialog. The way I read
> the Qt docs, you can use multiple file type filters in the dialog by using
> ;; as a separator between
> the type lists in the filter string. Like this:
>
> def fileOpen(self):
> filename = QFileDialog.getOpenFileNames("", "JPG (*.jpg);;PGM
> (*.pgm)"), self, "Read file", "Read file")
> ...
>
> I've found several examples on the net (C++ though, not Python) which do
> this, so I figured it should work,
> but what I got instead of three filters: "JPG (*.jpg)", "PGM (*.pgm)", and
> the default "All Files (*)", were three filters
> of which two were identical instances "JPG (*.jpg);;PGM (*.pgm)", and the
> third the default one. Any idea what
> the problem is here? I'm using Qt 3.3.3 and PyQt 3.13.
>
Never mind, found it. For some bizarre reason getOpenFileName and
getOpenFileNames have a reversed order for
the path and filter arguments. So for it to work, the code should be:
def fileOpen(self):
filename = QFileDialog.getOpenFileName("", "JPG (*.jpg);;PGM
(*.pgm)"), self, "Read file", "Read file")
if you want to read a single file, or if you want several, it should be:
def fileOpen(self):
filename = QFileDialog.getOpenFileNames( "JPG (*.jpg);;PGM (*.pgm)"),
"", self, "Read files", "Read files")
Strange, but it works.
--
Alex Borghgraef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060421/70a715d8/attachment.html
More information about the PyQt
mailing list