[PyQt] Qfiledailoug multiple file selection

klia alwaseem307ster at yahoo.com
Mon Mar 9 07:52:53 GMT 2009



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)
			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?!
-- 
View this message in context: http://www.nabble.com/Qfiledailoug-multiple-file-selection-tp22369488p22408007.html
Sent from the PyQt mailing list archive at Nabble.com.




More information about the PyQt mailing list