I'd like to draw a custom item delegate, which follows the current style. But there are differences between "WindowsVista/7" style and "WindowsClassic" for text color.
Im using the following code for drawing the background (working):
void FriendItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
QSize hint = sizeHint(opt, index);
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);
...
}
How to draw the text in correct color?
I can't use style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
to draw the whole item, because I have to draw more special text than one text line. (This function would paint the colors correctly.)
I tried with style->drawItemText(painter, opt.rect, opt.displayAlignment, opt.palette, true, "Hello World!");
but it paints always black. And for painter->drawText()
, I have no idea how to set the correct pen color.
QAbstractItemModel::setData()
withQt::ForegroundRole
. – Mckelvey