How do I display images in QListView of size of standard thumbnail size like 250 x 200 , and file nametext should wrap to next line , right now the images displayed are very small and are not positioned under each other in proper row column order.

Qt Code:
  1. import sys
  2. import os
  3.  
  4. from PyQt4 import QtGui, QtCore
  5.  
  6. class MyListModel(QtCore.QAbstractListModel):
  7. def __init__(self, datain, parent=None, *args):
  8. """ datain: a list where each item is a row
  9. """
  10. QtCore.QAbstractListModel.__init__(self, parent, *args)
  11. self.listdata = datain
  12.  
  13. def rowCount(self, parent=QtCore.QModelIndex()):
  14. return len(self.listdata)
  15.  
  16. def data(self, index, role):
  17. s = QtCore.QSize(250, 200)
  18. if index.isValid() and role == QtCore.Qt.DecorationRole:
  19. return QtGui.QIcon(QtGui.QPixmap(self.listdata[index.row()]).scaled(s))
  20. if index.isValid() and role == QtCore.Qt.DisplayRole:
  21. return QtCore.QVariant(os.path.splitext(os.path.split(self.listdata[index.row()])[-1])[0])
  22. else:
  23. return QtCore.QVariant()
  24.  
  25. class MyListView(QtGui.QListView):
  26. """docstring for MyListView"""
  27. def __init__(self):
  28. super(MyListView, self).__init__()
  29. # show in Icon Mode
  30. self.setViewMode(QtGui.QListView.IconMode)
  31. crntDir = "/Users/userName/Pictures/"
  32. # create table
  33. list_data = []
  34. philes = os.listdir(crntDir)
  35. for phile in philes:
  36. if phile.endswith(".png") or phile.endswith("jpg"):
  37. list_data.append(os.path.join(crntDir, phile))
  38. lm = MyListModel(list_data, self)
  39. self.setModel(lm)
  40. self.show()
  41.  
  42. if __name__ == '__main__':
  43. app = QtGui.QApplication(sys.argv)
  44. window = MyListView()
  45. window.show()
  46. window.raise_()
  47. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode