Originally Posted by
ChrisW67
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.
def data(self, index, role):
if index.isValid() and role == QtCore.Qt.DecorationRole:
row = index.row()
column = index.column()
value = self._listdata[row][column]
key = "image:%s"% value
# pixmap.load(value)
pixmap=self.generatePixmap(value)
# pixmap.scaled(400,300, QtCore.Qt.KeepAspectRatio)
if index.isValid() and role == QtCore.Qt.DisplayRole:
row = index.row()
column = index.column()
value = self._listdata[row][column]
fileName = os.path.split(value)[-1]
return os.path.splitext(fileName)[0]
def generatePixmap(self, value):
pixmap.load(value)
pixmap.scaled(100, 120, QtCore.Qt.KeepAspectRatio)
return pixmap
def data(self, index, role):
if index.isValid() and role == QtCore.Qt.DecorationRole:
row = index.row()
column = index.column()
value = self._listdata[row][column]
key = "image:%s"% value
pixmap = QtGui.QPixmap()
# pixmap.load(value)
if not QtGui.QPixmapCache.find(key, pixmap):
pixmap=self.generatePixmap(value)
QtGui.QPixmapCache.insert(key, pixmap)
# pixmap.scaled(400,300, QtCore.Qt.KeepAspectRatio)
return QtGui.QImage(pixmap)
if index.isValid() and role == QtCore.Qt.DisplayRole:
row = index.row()
column = index.column()
value = self._listdata[row][column]
fileName = os.path.split(value)[-1]
return os.path.splitext(fileName)[0]
def generatePixmap(self, value):
pixmap=QtGui.QPixmap()
pixmap.load(value)
pixmap.scaled(100, 120, QtCore.Qt.KeepAspectRatio)
return pixmap
To copy to clipboard, switch view to plain text mode
Bookmarks