def __init__(self, parent=None): QtGui.QListView.__init__(self, parent) self.setViewMode(QtGui.QListView.IconMode) # Reflow the image grid after resize self.setResizeMode(QtGui.QListView.Adjust) # Set a few pixel space between the thumbnails self.setSpacing(5) # All items uses the same size, this supposedly improves performance self.setUniformItemSizes(True) # Generate images from left to right self.setFlow(QtGui.QListView.LeftToRight) self.imageviewpopup = ImageViewerPopup() self.connect(self, QtCore.SIGNAL("activated (const QModelIndex&)"), self.click) # TODO enable this #self.addContextMenu() # This does not seem to do anything # most likely because of QTBUG-7232 self.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)
class ThumbnailGridView(QtGui.QListView): def __init__(self, parent=None): QtGui.QListView.__init__(self, parent) self.setViewMode(QtGui.QListView.IconMode) # Reflow the image grid after resize self.setResizeMode(QtGui.QListView.Adjust) # Set a few pixel space between the thumbnails self.setSpacing(5) # All items uses the same size, this supposedly improves performance self.setUniformItemSizes(True) # Generate images from left to right self.setFlow(QtGui.QListView.LeftToRight) self.imageviewpopup = ImageViewerPopup() self.connect(self, QtCore.SIGNAL("activated (const QModelIndex&)"), self.click) # TODO enable this #self.addContextMenu() # This does not seem to do anything # most likely because of QTBUG-7232 self.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel) def addContextMenu(self): """ Create & connect the QActions of the right-click menu """ self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.action1 = QtGui.QAction("Menu item1", self) self.addAction(self.action1) self.connect(self.action1, QtCore.SIGNAL("triggered()"), self.rightClick) def click(self, index): """ Handle the click event on a thumbnail. Show the imageviewer popup """ thumbnail = index.data(QtCore.Qt.DisplayRole) logging.info("Thumbnail clicked %s", thumbnail.path) self.imageviewpopup.setImage(thumbnail.path) self.imageviewpopup.show() def rightClick(self): photo = self.currentIndexToPhoto() print photo.path def currentIndexToPhoto(self): """ Convert current QModelIndex object to Photo """ # Get the index of the currently selected photo index = self.currentIndex() # get the object of the currently selected photo photoobj = index.data(QtCore.Qt.DisplayRole) return photoobj