Quote Originally Posted by ChrisW67 View Post
Every time the view asks for the Qt:ecorationRole you load a pixmap from a file, scale it, convert it to a QImage, and return it. None of those operations is cheap, some of them unnecessary. Take a look at QPixmapCache
I tried this below, but it still seems to slow.
Qt Code:
  1. def data(self, index, role):
  2.  
  3. if index.isValid() and role == QtCore.Qt.DecorationRole:
  4. row = index.row()
  5. column = index.column()
  6. value = self._listdata[row][column]
  7. key = "image:%s"% value
  8. pixmap = QtGui.QPixmap()
  9. # pixmap.load(value)
  10. if not QtGui.QPixmapCache.find(key, pixmap):
  11. pixmap=self.generatePixmap(value)
  12. QtGui.QPixmapCache.insert(key, pixmap)
  13. # pixmap.scaled(400,300, QtCore.Qt.KeepAspectRatio)
  14. return QtGui.QImage(pixmap)
  15.  
  16. if index.isValid() and role == QtCore.Qt.DisplayRole:
  17. row = index.row()
  18. column = index.column()
  19. value = self._listdata[row][column]
  20. fileName = os.path.split(value)[-1]
  21. return os.path.splitext(fileName)[0]
  22.  
  23. def generatePixmap(self, value):
  24. pixmap=QtGui.QPixmap()
  25. pixmap.load(value)
  26. pixmap.scaled(100, 120, QtCore.Qt.KeepAspectRatio)
  27. return pixmap
To copy to clipboard, switch view to plain text mode