You are not logged in.

Dear visitor, welcome to KDE-Forum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, April 6th 2004, 12:30pm

background color for each list view item

Hi,
How do i set the background color of a list view item in a list view using paint cell function?
I have overridden paintcell function of QListviewItem.
i have to change the background color of the listview items in an alternate fashion..i.e green- yelow- green- yellow..etc..

Thanks in advance, :D
Veena.

m4ktub

Intermediate

Posts: 257

Location: Lisbon, Portugal

Occupation: Software Engineer

  • Send private message

2

Friday, April 9th 2004, 10:05am

You can check the listview examples that come with QT. There it only changes the color of the text for unread items but the concept is the same.

It is something like
[code:1]
void <something>&#58;&#58;paintCell&#40; QPainter *p, const QColorGroup &cg,
int column, int width, int alignment &#41;
&#123;
QColorGroup _cg&#40; cg &#41;;
QColor c = _cg.background&#40;&#41;;

if &#40;<some count> % 2&#41;
_cg.setColor&#40; QColorGroup&#58;&#58;Background, Qt&#58;&#58;lightGray &#41;;

QListViewItem&#58;&#58;paintCell&#40; p, _cg, column, width, alignment &#41;;

_cg.setColor&#40; QColorGroup&#58;&#58;Background, c &#41;;
&#125;
[/code:1]

3

Sunday, April 11th 2004, 4:28pm

use KListView and KListViewItem

The KDE classes supports that out of the box, and even uses the colors configured by the user.