Search code examples
pythonpyqt4qlistwidgetitem

How to increase the size of a thumbnail in QListWidget


Problem => I would like to create a QlistWidgetItem object containing a list of images as well as their thumbnails at a relatively larger size than the current one I have (sorta like the "medium icons" or "large icons" option in windows explorer)

Progress So far => I have managed to find out how to create the list and all but the icons are far too small.

what I have tried => I've tried changing the font size of the list items assuming tht cld also make the font grow bigger proportionally. Didn't work. I've also tried setting the size of the thumbnail using (PIL's Image) according to another online blogger but that didnt work as well.

Code Snippet => #Imported Image and ImageQt from PIL and also imported QtGui and QtCore

    testimages = glob.glob(dirname +  "/*.jpg")
    # Create a list item for each image file,
    # setting the text and icon appropriately
    for image in testimages:
        picture = Image.open(image)
        picture.thumbnail((128,128), Image.ANTIALIAS)
        icon = QIcon(QPixmap.fromImage(ImageQt.ImageQt(picture)))
        item = QListWidgetItem(image, self)
        item.setIcon(icon)
        fonter = QFont("Times New Roman")
        fonter.setPointSize(14)
        item.setFont(fonter)

Hope you guys can help me out. :)


Solution

  • Define your desired size using setIconSize on your QListWidget.