Fixed: Delegate stops Model data background role color being painted
Hi Guys
I'm applying a delegate to a treeView but when I do it cancels out the background role of the data in the model represented by QModelIndex.
If I get the QBrush value of the background role and then try the code below, it still doesn't fill in the background of the cell with the color.
Can anyone tell me how to fix this?
Thanks
Jeff
Code:
{
QString currDescription
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
QBrush backgroundBrush
= index.
model()->data
(index, Qt
::BackgroundRole).
value<QBrush>
();
QString dataDescription
= QString("%1 %2").
arg(globalVal, currDescription
);
myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
// none of these set the background color back to that of the index background role
// myOption.palette.setBrush(QPalette::Window, backgroundBrush);
// or
// myOption.palette.setBrush(QPalette::Base, backgroundBrush);
// or
painter->setBackground(backgroundBrush);
drawDisplay(painter, myOption, myOption.rect, dataDescription);
}
Added after 1 1:
Fixed.
I didn't realize I needed QItemDelegate drawbackground as well.
Cheers
Jeff