@Rachol : Indeed it makes sense that it did not work with the color ! It works fine with the backgroundRole for the color, so it is a probleme with the pixmap.
@Santosh : I'm supplying it from my model, I don't have a custom delegate
@Rachol : Indeed it makes sense that it did not work with the color ! It works fine with the backgroundRole for the color, so it is a probleme with the pixmap.
@Santosh : I'm supplying it from my model, I don't have a custom delegate
post you undated code which returns pixmap..
For BackgroundRole you must always return QBrush. You can use void QBrush::setTexture ( const QPixmap & pixmap ) to set the image use to draw your background. But then it must be a correct size, so it is not drawn couple of times.
The only reasonable solution would be to subclass QStyledItemDelagate (not QItemDelegate) and reimplement paint method. If you have painted a QWidget before, this should be very straight forward.
Use setItemDelegateForColumn method to set a delegate on your TableView
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:
class ImageDelegate(QtGui.QStyledItemDelegate): def __init__(self, parent): QtGui.QStyledItemDelegate.__init__(self, parent) def paint(self, painter, option, index): # Get Item Data path = "path\to\my\image.jpg" opt.rect = option.rect painter.drawPixmap(opt.rect, pixmap)To copy to clipboard, switch view to plain text mode
And I call it like this :
Qt Code:
self.delegateImage = ImageDelegate(self) 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 ?
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:
opt.rect = option.rectTo 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?
Filling the cells with a color works fine :
Qt Code:
To copy to clipboard, switch view to plain text mode
But still no changes with the pixmap
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.
Bookmarks