[PyKDE] coloured QTable

Jens Nie linux.wg at t-online.de
Sat Jul 14 13:14:54 BST 2001


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




More information about the PyQt mailing list