Results 1 to 14 of 14

Thread: QTableView with a column of images

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Location
    Paris
    Posts
    9
    Qt products
    Platforms
    Windows

    Default Re: QTableView with a column of images

    I'm trying something with a delegate but so far I got nothing, maybe you can help me to get this straight.
    I created a custom delegate inheriting QStyledItemDelegate :
    Qt Code:
    1. class ImageDelegate(QtGui.QStyledItemDelegate):
    2.  
    3. def __init__(self, parent):
    4. QtGui.QStyledItemDelegate.__init__(self, parent)
    5.  
    6. def paint(self, painter, option, index):
    7. # Get Item Data
    8.  
    9. path = "path\to\my\image.jpg"
    10.  
    11. style = QtGui.QApplication.style()
    12. opt.rect = option.rect
    13. pixmap = QtGui.QPixmap(path)
    14.  
    15. painter.drawPixmap(opt.rect, pixmap)
    To copy to clipboard, switch view to plain text mode 

    And I call it like this :
    Qt Code:
    1. self.delegateImage = ImageDelegate(self)
    2. self.setItemDelegateForColumn(2, self.delegateImage)
    To copy to clipboard, switch view to plain text mode 

    And I am sure the path is correct

    What am I missing ?

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QTableView with a column of images

    Okay, I am not a specialist on python, couldn't even call myself a beginner. However I think you don't need this:
    Qt Code:
    1. style = QtGui.QApplication.style()
    2. opt.rect = option.rect
    To copy to clipboard, switch view to plain text mode 

    Just use option.rect directly.

    Appart from that there is nothing I could say is wrong or unnecessary. Have you tried to fill option.rect with some color?

  3. #3
    Join Date
    May 2011
    Location
    Paris
    Posts
    9
    Qt products
    Platforms
    Windows

    Default Re: QTableView with a column of images

    Filling the cells with a color works fine :

    Qt Code:
    1. painter.fillRect(option.rect, QtGui.QColor(191,222,185))
    To copy to clipboard, switch view to plain text mode 

    But still no changes with the pixmap

  4. #4
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QTableView with a column of images

    The there are only 2 things can go wrong:

    1. Your pixmap is not loaded(wrong path)
    2. Your pixmap is not scalled to the size of the area you are drawing into.

Similar Threads

  1. how to disbale a column in a QTableView
    By rdjenner in forum Qt Programming
    Replies: 8
    Last Post: 14th August 2019, 15:44
  2. QTableView set column Decimals
    By ottoshmidt in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2010, 05:00
  3. Currently sorted column in QTableView
    By borges in forum Newbie
    Replies: 1
    Last Post: 21st September 2007, 16:52
  4. Fixating column from QTableView ?
    By pinktroll in forum Qt Programming
    Replies: 2
    Last Post: 4th September 2007, 10:53
  5. QTableView without the first counter column?
    By pmaktieh.sirhc in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2007, 22:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.