本文整理汇总了Python中PySide.QtGui.QIcon.cacheKey方法的典型用法代码示例。如果您正苦于以下问题:Python QIcon.cacheKey方法的具体用法?Python QIcon.cacheKey怎么用?Python QIcon.cacheKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QIcon
的用法示例。
在下文中一共展示了QIcon.cacheKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QListAlbum
# 需要导入模块: from PySide.QtGui import QIcon [as 别名]
# 或者: from PySide.QtGui.QIcon import cacheKey [as 别名]
class QListAlbum(LibraryListView):
def __init__(self, strategy):
LibraryListView.__init__(self, strategy)
self.setGridSize(QtCore.QSize(128,148))
self.setIconSize(QtCore.QSize(100,100))
self.setUniformItemSizes(True)
self.setObjectName('albums')
self.setViewMode(QListView.IconMode)
self.setResizeMode(QListView.Adjust)
self.verticalScrollBar().valueChanged.connect(self.reload)
self.placeholder = QIcon(':img/placeholder.jpg')
self.loaded_icons = []
def resizeEvent(self, event):
QListView.resizeEvent(self, event)
self.reload()
def add(self, album):
item = LibraryListView.add(self, album)
item.setIcon(self.placeholder)
def filter(self, field, value):
self.unload()
LibraryListView.filter(self, field, value)
self.load()
def load(self):
indexes = []
height = self.size().height() + 128
x, y = 64, 64
index = self.indexAt(QtCore.QPoint(x,y))
while index.isValid() and y < height:
indexes.append(index)
while index.isValid():
indexes.append(index)
x += 128
index = self.indexAt(QtCore.QPoint(x,y))
x = 64
y += 148
index = self.indexAt(QtCore.QPoint(x,y))
for id in indexes:
modelindex = self.model().mapToSource(id)
album = modelindex.data(ModelToItemStrat.PLAY)
item = self.model().sourceModel().itemFromIndex(modelindex)
self.loaded_icons.append(id)
if item.icon().cacheKey() == self.placeholder.cacheKey():
artwork = album.get_art()
if artwork:
item.setIcon(QIcon(artwork))
def unload(self):
for id in self.loaded_icons:
viewport = self.viewport().rect()
modelindex = self.model().mapToSource(id)
item = self.model().sourceModel().itemFromIndex(modelindex)
item.setIcon(self.placeholder)
self.loaded_icons = []
def reload(self):
for id in self.loaded_icons:
viewport = self.viewport().rect()
if not viewport.contains(self.visualRect(id)):
modelindex = self.model().mapToSource(id)
item = self.model().sourceModel().itemFromIndex(modelindex)
item.setIcon(self.placeholder)
self.loaded_icons = []
self.load()