Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Place Image in PyQt QTableWidget Header
Forum Updated to NodeBB v4.3 + New Features

Place Image in PyQt QTableWidget Header

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luke.whitehorn
    wrote on last edited by
    #1

    I am trying to create a QTableWidget that has a thumbnail image in it's vertical header (and eventually some text under it). My current attempt is to subclass the QTableWidgetItem...

    class ShotHeader(qt.QTableWidgetItem):
        imagePath = os.path.join(r'T:\path\to\image.jpg')
        shotThumbnailPixMap = QPixmap(imagePath).scaledToWidth(60)
    
        def __init__(self):
            super(ShotHeader, self).__init__()
            self.setData(QtCore.Qt.DecorationRole, self.shotThumbnailPixMap)
    

    And later on this is set via

    shotInterface = QTableWidget(rows, cols)
    for row in range(rows):
        shotInterface.setVerticalHeaderItem(row, ShotHeader())
    

    Which does show the image, but it seems to be an icon which I cannot change the size of, as can be seen in the following image...

    Tiny thumbnail images which will not change.

    Obviously, I'm looking for a way to make the images a decent size,
    I have searched quite extensively for a solution to this problem, but have so far come up with nothing. No amount of scaling the QPixmap has any effect.
    I'd really appreciate some help on this.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      my "guess" is that the available space reserved by the table is the limiting factor. Remember, everything is governed by layouts and their constraints. you mention scaling of the pixmap, but what happens if you set its size constraint values; specifically its minimumSize()?

      L 1 Reply Last reply
      0
      • Kent-DorfmanK Kent-Dorfman

        my "guess" is that the available space reserved by the table is the limiting factor. Remember, everything is governed by layouts and their constraints. you mention scaling of the pixmap, but what happens if you set its size constraint values; specifically its minimumSize()?

        L Offline
        L Offline
        luke.whitehorn
        wrote on last edited by
        #3

        @Kent-Dorfman From the docs for QPixmap and QTableWidgetItem (which I'm using as the vertical header) there doesn't seem to be any functions to set or examine minimum size.
        I've also tried setSizeHint for the QTableWidgetItem.
        Nothing will change he icon size.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luke.whitehorn
          wrote on last edited by
          #4

          Anyone have any clues at all?
          As you can see from my Stack Exchange question here a user showed that he managed to do it, but then he disappeared.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved