[Qt-interest] How to set the color to listview item names

Andre Somers andre at familiesomers.nl
Wed Jun 2 09:17:01 CEST 2010


On 2-6-2010 8:09, Ramesh wrote:
>
> Hi,
>
> I am interested in placing the different color to item names in listview.
>
> How to do color changing to items in listview?.
>
> For example I have two items in listview, by default the color will be 
> black, but I want it to be blue.
>
> How can I do that?
>
> Thanks in advance
>
>
If you want to color the whole item, you can do that using the 
Qt::ForegroundRole to return the right color from the models data() 
method. If you don't want to modify the model, you can either use a 
proxy model in between the view and the model, or use a QItemDelegate 
subclass.

If you want to color only part of the text in the item, you're talking 
about rich text. That is quite a bit more complex and requires custom 
delegates unfortunately. I wrote such a rich text delegate, and I am 
working on a delegate on top of that to enable the use of style sheets 
to style items. That should make this kind of thing very easy to do (a 
two-liner), but it is not ready yet.

André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100602/de2e1668/attachment.html 


More information about the Qt-interest-old mailing list