PDA

View Full Version : QStyledItemDelegate background color



Alundra
18th January 2015, 00:51
Hi all,
Is it possible to know the background color in QStyledItemDelegate on this function ?

void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
I would draw the item with a width less the icon size, the icon has transparent color around so the selection color or background of the widget has to be renderer on a rect.
I know the size of the rect, I know how paint more little, only know the good color is missing.
Is it possible to know the code needed ?
Thanks for the help

ChrisW67
18th January 2015, 21:10
You can access the colour roles of the model index being drawn to get model's suggestion if any. The option parameter carries a palette member variable (QPalette) that gives the various style/system defined colours

Alundra
19th January 2015, 00:10
Works good, I tried QPalette since beginning but I used QPalette::Background which doesn't works, QPalette::Window has to be used :


QBrush Background;
if( ( itemOption.state & QStyle::State_Selected ) || ( itemOption.state & QStyle::State_MouseOver ) )
Background = itemOption.palette.highlight();
else
Background = itemOption.palette.window();