[PyQt] Qfiledailoug multiple file selection
Detlev Offenbach
detlev at die-offenbachs.de
Mon Mar 9 17:30:23 GMT 2009
On Montag, 9. März 2009, klia wrote:
> Detlev Offenbach wrote:
> > On Samstag, 7. März 2009, klia wrote:
> >> Detlev Offenbach wrote:
> >> > On Freitag, 6. März 2009, klia wrote:
> >> >> Hey folks;
> >> >>
> >> >> How can i be able to select multiple files whenever i browse my
> >> >> directory using QfileDailoug?
> >> >>
> >> >> this is the code to call up the filedailoug
> >> >>
> >> >> files = QtGui.QFileDialog.getOpenFileName(self, 'Open
> >> >> file','/home/', ("Images (*.png *.tiff *.jpg)"))
> >> >
> >> > Just use "getOpenFileNames(...)". See the docs for more details.
> >> >
> >> >> Thank you
> >> >
> >> > --
> >> > Detlev Offenbach
> >> > detlev at die-offenbachs.de
> >> >
> >> > _______________________________________________
> >> > PyQt mailing list PyQt at riverbankcomputing.com
> >> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> >>
> >> Thank you Detlev Offenbach it worked but python complaining that there's
> >> no
> >> buffer or string to hold the selected files in order to process
> >> them...............Any idea
> >
> > Just call it like this:
> >
> > fileNames = QFileDialog.getOpenFileNames(\
> > self,
> > self.trUtf8("Add Documentation"),
> > QString("/home"),
> > self.trUtf8("Qt Compressed Help Files (*.qch)"))
> >
> > Detlev
> > --
> > Detlev Offenbach
> > detlev at die-offenbachs.de
> >
> > _______________________________________________
> > PyQt mailing list PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
> hello Detlev
>
> I am supposed to select multiple files and list them on listwidget but i am
> able only to select one file and list it on listwidget using this code
>
> files = QtGui.QFileDialog.getOpenFileName(self, 'Open file','/home/',
> ("Images (*.png *.tiff *.jpg)"))
> data=""
> if(files):
> file=open(files)
> data = file.read()
> self.listWidget.addItem(files)
>
> but when i pasted your code
> files = QFileDialog.getOpenFileNames(self, self.trUtf8("Add
> documentation"), QString("/home"), self.trUtf8("Images (*.png *.tiff
> *.jpg)"))
> data=""
> if(files):
> file=open(files)
files is a QStringList. Your code should be something like this:
for file_ in files:
data = ""
f = open(file_)
data = file.read()
self.listWidget.addItem(file_)
Alternatively you may use "self.listWidget.addItems(files)" to add them all in
one go. Please read the Qt documentation. It will give you details about the
API. A good tutorial like the one written by Roberto Alsina (s. this list for
details) would help as well.
> data = file.read()
> self.listWidget.addItem(files)
>
> python returned this error
> waseem at home:~/Desktop/Project2/GUI$ python wrapphotodb.py
> Traceback (most recent call last):
> File "wrapphotodb.py", line 50, in _actionImport_Photos
> file=open(files)
> TypeError: coercing to Unicode: need string or buffer, QStringList found
>
> plus what do you mean by Add Documentation in your code?!
That is just an example for the dialog's title.
Detlev
--
Detlev Offenbach
detlev at die-offenbachs.de
More information about the PyQt
mailing list