[PyQt] Background color for cells in QTableView

Marc Rossi mrossi19 at gmail.com
Fri Jun 24 20:30:32 BST 2011


I have a model/view app with a QTableView that I would like to have columns
2, 3 & 4 shaded a different color than the rest.  My model sub-classes
QAbstractTableModel and I also use a QSortFilterProxyModel.   I assumed I
could just override the data() method in my QAbstractTableModel derived
class, returning the correct QBrush when called with role =
Qt.BackgroundRole, but my data method NEVER gets called with this role.
I currently use a stylesheet to set the entire background of the QTableView.

Not a Qt expert by any means but when I call model.roleNames() and print out
the results I only see roles 0-5, no role 8 (Background).  Not sure if this
call returns all roles supported by the model or if it is just there as a
utility func.

Any help would be greatly appreciated.

Marc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110624/bd4ff243/attachment.html>


More information about the PyQt mailing list