[PyKDE] Colour a cell in QTableView (PyQt4)
Chris Dunscombe
cdunscombe at yahoo.com
Thu Sep 21 18:29:39 BST 2006
--- Andreas Pakulat <apaku at gmx.de> wrote:
> On 21.09.06 03:27:04, Chris Dunscombe wrote:
> > I'm trying to set the colour of cell in a QTableView, not all cells the same colour. I'm using
> a
> > model with a delegate. I've looked at the docs and googled around and can't work out any
> > reasonable way to do it. In PyQt3 it was fairly easy as I just sub-classed QTable and
> > re-implemented paintCell.
>
> It's easy with Qt4 too, in your model return the proper color if role ==
> Qt.BackgroundColorRole and the index is the one you want the color
> changed for. Of course if your custom delegate paints the cells, you
> need to ask the model for the background role data in the painting
> function. Look at the QItemDelegate's painting function to get an idea.
>
Thanks for that pointer. However I'm still struggling. My custom delegate does paint the cell and
I've looked at QItemDelegate.paint(). I assume I need to re-implement this function, which I've
done, but I don't have any idea what I should actually code to set the colour. I tried creating my
own QBrush and setting it's colour etc.
def paint(self, painter, option, index)
myBrush = QBrush()
myBrush.setColor(Qt.Yellow)
painter.setBrush(myBrush)
QItemDelegate(self, painter, option, index)
but this did nothing.
If possible could you include a few lines of code that does this.
Thanks very much,
Chris
> Andreas
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the PyQt
mailing list