I have QListView with a custom delegate
Custom delegate paint method:
QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt,index);
opt.decorationSize = QSize(deco_size,deco_size);
opt.decorationAlignment |= Qt::AlignCenter;
opt.displayAlignment |= Qt::AlignCenter;
opt.decorationPosition = QStyleOptionViewItem::Top;
opt.font.setBold(true);
const QWidget *widget = opt.widget;
QStyle *style = widget ? widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem,&opt,painter);
My problem is that If I set stylesheet for my QListView::item e.g.:
#lv::item:selected:active { background: red; }
it won't work!
If I'm using internal, none custom delegate everything is fine.
2. I only use custom delegate to put the decoration icon to the top of the text, is there a stylesheet option to force the icon to appear on top?
I missed the 4th parameter of QStyle::drawControl function "widget":
style->drawControl(QStyle::CE_ItemViewItem,&opt,painter,widget);
Here, QStyledItemDelegate source code, paint method: