PDA

View Full Version : QTreeWidgetItem background



subratatamal
16th September 2008, 13:24
QTreeWidgetItem *familyItem = new QTreeWidgetItem(fontTree);


familyItem->setText(0, family);
familyItem->setCheckState(0, Qt::Unchecked);
familyItem->setBackground(0,QColor(202, 0, 0, 255));

I want to color each item,but setbackground is changing only the color of first item.Any guess,why its not painting the item?.Looking for help

aamer4yu
16th September 2008, 13:33
setBackground takes column as the first argument.
If you want to set color for the whole row, u will need to call setBackground on all columns :)

subratatamal
16th September 2008, 13:38
Thanks for your reply.
I have only one column but n number of rows.My first row is getting the color.I want to color all the rows
Thanks

aamer4yu
16th September 2008, 20:25
I guess you will need to iterate all items and set the color.

Other mehtod is to use delegates. I tried using it, but was not able to set the background color.
QTreeWidget uses delegates to render the items. I used QItemDelegate, but its drawBackground function was not being called. Only paint() was called. Also tried QStyledItemDelegate, but it doesnt have drawBackground function. Seems have to use paint() only.. :(

I will let u know if i succeed. its late now... gotta sleep