[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyKDE] Re: QFileDialog.getOpenFileName with multiple filters
From: "Alexander Borghgraef" <alexander.borghgraef.rma () gmail ! com>
Date: 2006-04-21 12:09:01
Message-ID: 9e8c52a20604210509xb39cd28ye0d003f52f032a04 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On 4/21/06, Alexander Borghgraef <alexander.borghgraef.rma@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
[Attachment #5 (text/html)]
On 4/21/06, <b class="gmail_sendername">Alexander Borghgraef</b> <<a \
href="mailto:alexander.borghgraef.rma@gmail.com">alexander.borghgraef.rma@gmail.com</a>> \
wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" \
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; \
padding-left: 1ex;"> <div style="direction: ltr;">Hi all,<br>
<br>
I'm trying to read in files in my PyQt app, so naturally I'm using QFileDialog. \
The way I read<br> the Qt docs, you can use multiple file type filters in the dialog \
by using ;; as a separator between<br> the type lists in the filter string. Like \
this:<br> <br>
def fileOpen(self):<br>
filename =
QFileDialog.getOpenFileNames("", "JPG (*.jpg);;PGM (*.pgm)"), \
self, "Read file", "Read file")<br>
...<br>
<br>
I've found several examples on the net (C++ though, not Python) which do this, \
so I figured it should work,<br> but what I got instead of three filters: "JPG \
(*.jpg)", "PGM (*.pgm)", and the default "All Files (*)", \
were three filters<br> of which two were identical instances "JPG (*.jpg);;PGM \
(*.pgm)", and the third the default one. Any idea what<br> the problem is \
here? I'm using Qt 3.3.3 and PyQt 3.13. \
</div></blockquote><div><br> Never mind, found it. For some bizarre reason \
getOpenFileName and getOpenFileNames have a reversed order for<br> the path and \
filter arguments. So for it to work, the code should be:<br> <br>
def fileOpen(self):<br>
filename =
QFileDialog.getOpenFileName("", "JPG (*.jpg);;PGM (*.pgm)"), \
self, "Read file", "Read file")<br>
<br>
if you want to read a single file, or if you want several, it should be:<br>
<br>
def fileOpen(self):<br>
filename =
QFileDialog.getOpenFileNames( "JPG (*.jpg);;PGM (*.pgm)"), "", \
self, "Read files", "Read files")<br>
<br>
</div>Strange, but it works.<br></div><br>-- <br>Alex Borghgraef
_______________________________________________
PyKDE mailing list PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic