I have an external database with images of products. Is it possible to import these images and display them in a scrolling list, as well as making them user clickable, similar to how a file browser works?
I can only find information on people converting to resource files, but I wonder if its possible to skip that?
Ok ListView and ListWidget both allow users to display content in either list Mode or Icon Mode. So you can set the view mode to icon mode and display image in the list View.
self.listView.setViewMode(QtGui.QListView.IconMode)
or
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
put the above code outside your class.
self.listWidget.setViewMode(QtGui.QListView.IconMode)
item = QtGui.QListWidgetItem()
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/sameold/capture_14.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
item.setIcon(icon)
self.listWidget.addItem(item)
Here is the output for this .
import os
files=[]
for file in os.listdir("C:/"):
if file.endswith(".jpeg"):
files.append(os.path.join(os.getcwd(), file))
for x in files:
item = QtGui.QListWidgetItem()
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(x)), QtGui.QIcon.Normal, QtGui.QIcon.Off)
item.setIcon(icon)
self.listWidget.addItem(item)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With