PDA

View Full Version : Flash Table Cell Background Colour



stefanadelbert
25th May 2011, 07:57
I would like to be able to change the background colour (even animate the background colour) of a new item in a ListView when it's added to the model.

In particular, if a new item is added to the model, I would like it's background colour to be different (the highlight colour) for 5 seconds and then go back to the normal colour. If the highlight colour could fade back to the normal colour, that would be a bonus.

It would be nice if the colours were dictated by the qss, i.e. not hardcoded.

I imagined subclassing QStyledItemDelegate with an overidden paint function to draw the background (straightforward). Here is a decent read (http://taschenorakel.de/michael/2010/01/29/how-customize-your-view-delegates/) on QStyledItemDelegate.

The subclass could have a QTimer (started in the constructor) so that it could decide between painting the background the highlight colour or the normal colour. This only works if a QStyledItemDelegate is created for each cell and I can't work out from the documentation if that is the case. Is there only one instance of the delegate per view or is there one instance per (visible) index?

This article (http://doc.qt.nokia.com/qq/qq24-delegates.html#theappearanceofadelegate) suggests that there is only one instance of a delegate for multiple similar views, which would mean that the idea of a timer would not work.

Has anyone got any ideas on how to do this?

Santosh Reddy
20th July 2011, 09:08
QTimer concept will work, QTimer should live in model (or proxy model), Timer is created and started when an row is inserted into model, and it controls the background color over time, and eventually should stop and kill itelf. Also note to emit dataChanged() signal from model when the background color is changed (i.e. every time timer slot executes)