import PyQt4
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import Qt
from PyQt4.QtCore import SIGNAL
def __init__(self, image, parent=None):
self._image = image
self._loaded = False
def paint(self, painter, styleopt, widget):
if not self._loaded:
self._loaded = True
pixmap
= QtGui.
QPixmap(self._image
) thumb = pixmap.scaled(200, 200, Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.
setPixmap(QtGui.
QPixmap(self._image
).
scaled(200,
200))
def __init__(self, images, parent=None):
total = len(images)
current = 0
for image in images:
#print current, 'of', total, os.path.basename(image)
if os.path.isdir(image) or os.path.basename(image).startswith('.'):
continue
current += 1
item = QdGraphicsPixmapItem(image, current)
item.setPos(0, 200*current)
self._scene.addItem(item)
self._scene.setSceneRect(0, 0, 200, 200*current)
self.setScene(self._scene)
import PyQt4
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import Qt
from PyQt4.QtCore import SIGNAL
class QdGraphicsPixmapItem(QtGui.QGraphicsPixmapItem):
def __init__(self, image, parent=None):
QtGui.QGraphicsPixmapItem.__init__(self, parent)
self._image = image
self._loaded = False
self.setFlags(self.flags() | QtGui.QGraphicsItem.ItemIsSelectable | QtGui.QGraphicsItem.ItemIsMovable )
def paint(self, painter, styleopt, widget):
if not self._loaded:
self._loaded = True
pixmap = QtGui.QPixmap(self._image)
thumb = pixmap.scaled(200, 200, Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.setPixmap(QtGui.QPixmap(self._image).scaled(200, 200))
QtGui.QGraphicsPixmapItem.paint(self, painter, styleopt, widget)
class QdThumbnailView(QtGui.QGraphicsView):
def __init__(self, images, parent=None):
QtGui.QGraphicsView.__init__(self, parent)
self._scene = QtGui.QGraphicsScene()
total = len(images)
current = 0
for image in images:
#print current, 'of', total, os.path.basename(image)
if os.path.isdir(image) or os.path.basename(image).startswith('.'):
continue
current += 1
item = QdGraphicsPixmapItem(image, current)
item.setPos(0, 200*current)
self._scene.addItem(item)
self._scene.setSceneRect(0, 0, 200, 200*current)
self.setScene(self._scene)
To copy to clipboard, switch view to plain text mode
Bookmarks