[PyKDE] coloured QTable
Phil Thompson
phil at river-bank.demon.co.uk
Sat Jul 14 15:24:37 BST 2001
QTable doesn't take ownership of it's QTableItems, so the C++ QTableItem
gets destroyed when the corresponding Python object is garbage
collected.
Use "self.tableitem" rather than "tableitem" to keep the Python object
alive.
Phil
Jens Nie wrote:
>
> Hi.
>
> I need a Qtable in which the items have a background color.
> I know from the Qt Archive that i have to use a subclass of QTableItem with
> a reimplementation of the paint method to get this working. But actually this
> is not working. Here is the code:
>
> #!/usr/bin/env python
> import sys
> from qt import *
>
> class MyTableItem(QTableItem):
> def __init__(self, table, edittype, text):
> QTableItem.__init__(self, table, edittype, text)
> print "New MyTableItem"
>
> def paint(self, painter, colorgroup, rect, selected):
> print "paint called"
> cg = QColorGroup(colorgroup)
> cg.setColor(QColorGroup.Base, Qt.red)
> QTableItem.paint(painter, cg, rect, selected)
>
> class MyWidget(QTable):
> def __init__(self, parent=None, name="MyWidget"):
> QTable.__init__(self, 10, 4, parent, name)
>
> tableitem = MyTableItem(self,
> QTableItem.Never,
> "Hello Table")
> self.setItem(1, 1, tableitem)
>
> if __name__=="__main__":
> app = QApplication(sys.argv)
> mw = MyWidget()
> app.setMainWidget(mw)
> mw.show()
> app.exec_loop()
>
> When i start the application the upper left cell should have the string
> "Hello Table" with a red background, but hasn't.
> The only message is "New MyTableItem", but no "paint called" occurs.
>
> I don't really see the difference to the statistics example from the qt2
> package, which is working..
>
> Any ideas?
>
> Jens Nie
>
> _______________________________________________
> PyKDE mailing list PyKDE at mats.gmd.de
> http://mats.gmd.de/mailman/listinfo/pykde
More information about the PyQt
mailing list