[PyQt] TableView Cell Delegates

Cristobal Infante cgcris at gmail.com
Mon Oct 29 11:09:25 GMT 2012

Hi everyone,

I am struggling to get what seems to be a simple delegate working.

What I want is to change the background of a tableview cell, from what I
I should be looking at the Qt.BackgroundRole. So far I havent bee able to
get it working.

What I have so far, is a delegate that fills the cell with a color, but it
seems to be going
on top of the text:

class CellBackgroundColor(QtGui.QStyledItemDelegate):

    def __init__(self, parent = None):
        QtGui.QStyledItemDelegate.__init__(self, parent)

    def paint(self, painter, option, index):

        path = index.model().data(index,  QtCore.Qt.DisplayRole).toString()
        painter.fillRect(option.rect, QtGui.QColor(path))

Any ideas on how to implement this Qt.BackgroundRole in a tableview

Thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121029/04e3754d/attachment.html>

More information about the PyQt mailing list