First of all, I'm using PyQt4 4.4.3, python 2.6.2, and Qt 4.5.
I am trying to display pixmaps sortable by filename in a QTableView. If I try to pass a QVariant containing a pixmap from my custom model's data method and paint the pixmap in my custom delegate, the images show up perfectly, but sorting isn't possible.
As such, I've decided to instead pass a QVariant containing the file location of the image from my custom model's data method and convert it into a pixmap in the delegate. While sorting now works perfectly, the image is displayed behind the image's location.
I've tried painter.setCompositionMode(), painter.eraseRect(), painter.filRext(), painter.restore(), and painter.setFont() in CustomDelegate to no avail.
Is there some way to either cover the filename with the pixmap, change the fon't of the filename to transparent so that only the pixmap is shown, or clear the contents of the cell before painting the pixmap?
Below is my python code, but I know enough c++ that solutions given in c++ are acceptable. Thanks in advance.
from CustomItemDelegate:
...
def __init__(self, parent=None):
def paint(self, painter, option, index):
if index.column() == IMAGE:
painter.drawPixmap(option.rect,
QPixmap(index.
model().
data(index
).
toString()))
...
class CardItemDelegate(QItemDelegate):
def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
def paint(self, painter, option, index):
if index.column() == IMAGE:
painter.drawPixmap(option.rect,
QPixmap(index.model().data(index).toString()))
QItemDelegate.paint(self, painter, option, index)
To copy to clipboard, switch view to plain text mode
Bookmarks