Hi all,

I have just started using pyqt4 and decided to make a small
thumbnail-viewer to learn how things work.

I would like the thumbnails to be displayed in a grid that
automatically change the grid when resized so I use the QListWidget.
So far so good - it works fine ...almost... the thumbnails (QIcons)
are very small - how do I make them larger?

Code is attached.

Thanks!
Mads
#! /usr/bin/env python

from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys

TITLE = 'ThumbGridWidget'
THUMBWIDTH = 64
PICS = ['Elvis1.jpg',
		'Elvis2.jpg',
		'Elvis3.jpg',
		'Elvis4.jpg']*4

black   = QColor(0, 0, 0)
white   = QColor(255, 255, 255)
red     = QColor(255, 0, 0)
green   = QColor(0, 255, 0)
blue    = QColor(0, 0, 255)
yellow  = QColor(255, 255, 0)
cyan    = QColor(0, 255, 255)
magenta = QColor(255, 0, 255)





class Thumb(QListWidgetItem):

	def __init__(self, parent=None, imgPath='', title=''):
		super(Thumb, self).__init__(parent)

		pic = QPixmap(imgPath)
		icon = QIcon(pic)
		self.setIcon(icon)
		self.setText(title)



class ThumbListWidget(QListWidget):

	p = QPalette()

	def __init__(self, parent=None, palette=None):
		super(ThumbListWidget, self).__init__(parent)

		# Setup
		self.setViewMode(QListView.IconMode)
		self.setResizeMode(QListView.Adjust)
		self.setLayoutMode(QListView.SinglePass)
		self.setUniformItemSizes(1)
		self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

		# Colors
		if palette: self.p = palette
		self.setPalette(self.p)

		list = PICS
		for pic in list:
			thumb = Thumb(None, pic, pic)
			self.addItem(thumb)

	def setBackgroundColor(self, color):
		self.p.setColor(QPalette.Base, color)
		self.setPalette(self.p)

	def setTextColor(self, color):
		self.p.setColor(QPalette.Text, color)
		self.setPalette(self.p)




class Main(QMainWindow):
	
	def __init__(self, parent=None):
		super(QMainWindow, self).__init__(parent)

		self.setWindowTitle(TITLE)

		self.listView = ThumbListWidget(self)

		self.listView.setBackgroundColor(black)
		self.listView.setTextColor(white)

		self.setCentralWidget(self.listView)




if __name__ == "__main__":
	print "Starting.."
	app = QApplication(sys.argv)
	win = Main()
	win.show()
	app.exec_()
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to