Hey there,
I have a QTreeView and reimplemented a QStandardItemModel. For some special columns I want to display icons instead of text. So I rewrote QStandardItemModel::headerData(...). I should return a QVariant created with an Icon at these columns. But the icon is not shown in the QTreeView. Instead the header is empty there.
My code looks like this:
orientation,
role
);
if (result.
toString().
compare(QString("Special Column")) == 0) {
pixmap.fill(Qt::red);
result.setValue(icon);
}
return result;
QVariant result = QStandardItemModel::headerData( section,
orientation,
role
);
if (result.toString().compare(QString("Special Column")) == 0)
{
QPixmap pixmap = QPixmap(5, 5);
pixmap.fill(Qt::red);
QIcon icon = QIcon(pixmap);
result.setValue(icon);
}
return result;
To copy to clipboard, switch view to plain text mode
I tried it with returning a lot of different Variants (icon, string, pixmap etc.) but nothing except QString works.
Did I mised something?
Do I need to reimplement paint from HeaderView?
Thanks and happy new year to all of you,
bbg
Bookmarks