PDA

View Full Version : need help on changing color of particular items in QStandardItemModel



Askar
18th November 2009, 07:07
Dear friends,
I need help on changing color of particular items in QStandardItemModel. i am displaying inbox messages in a standard item model. i need to differentiate readed messages and unreaded messages with different background color......


thanks

Regards,
Askar

spirit
18th November 2009, 07:09
take a look at QStandardItem::setBackground.

Askar
19th November 2009, 12:09
Thanks for your reply ,
i tried but items background color is not changing,
please let me know where doing wrong in the following code

QDialog showdia = new QDialog;
while(q1.next())
{
model->insertRow(MsgIDlist.size());
for(int i=0;i<3;i++)
{
QStandardItem *item = new QStandardItem(q1.value(i).toString());
QBrush b;
b.setColor(Qt::gray);
item->setBackground(b);
model->setItem(MsgIDlist.size(),i,item);
}
}
q1.clear();
sourceView->setModel(model);
sourceLayout = new QHBoxLayout;
sourceLayout->addWidget(sourceView);
sourceGroupBox->setLayout(sourceLayout);
showdia->setFixedSize(300,220);
showdia->show();


Regards
Askar

NoRulez
19th November 2009, 14:10
Try something like the following:


model->setData(model->index(row, column), Qt::blue, Qt::BackgroundRole);


Best Regards
NoRulez