Frage

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?

War es hilfreich?

Lösung

I missed the 4th parameter of QStyle::drawControl function "widget":

style->drawControl(QStyle::CE_ItemViewItem,&opt,painter,widget);

Here, QStyledItemDelegate source code, paint method:

https://qt.gitorious.org/qt/webkit/source/435bbd4be73768f617e4a4083a345d1d8d62daa3:src/gui/itemviews/qstyleditemdelegate.cpp#L444

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top