pyqt table
Jim
jbublitzNO at SPAMnwinternet.com
Tue Nov 5 15:53:06 EST 2002
Rob Hall wrote:
> I have created a qt table fine. I want to be able to colour the background
> of individual cells but I cant find a setBackground method fot QTableItem.
> How do I colour the background of a cell?
I haven't done this in quite a while, but it
looks like you need to subclass QTableItem and
overload the paint method:
class CustomTableItem (QTableItem):
def __init__ (self, table, et, text):
QTableItem.__init__ (self, table, et, text)
def paint (self, p, cg, cr, selected):
if <some condition, like self.row () ==
or something based on cell value>
new_cg = <new QColorGroup defined by
your program somehow>
else:
new_cg = cg
QTableItem.paint (self, p, new_cg, cr, selected)
Each QTableItem holds row/col properties, so you
can use those to determine the row being painted.
(see QTableItem.row (), for example)
See the Qt docs for QTableItem::paint and QColorGroup.
There's also some example C++ code linked at
QTableItem.paint in the Qt docs.
Jim
More information about the Python-list
mailing list