PDA

View Full Version : Show Icons in Header of QTreeView



blackbubblegum
2nd January 2012, 13:32
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:



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;


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

blackbubblegum
4th January 2012, 16:27
No one, any idea?
Do you need further information?

mwoehlke
11th February 2012, 00:55
It seems to work for me, but note that you need to return the icon for DecorationRole instead of DisplayRole.