How to dispay an icon in the first column of QTreeView
Hi!
Here is what i need: Display an icon in the first column of QTreeView. Icon should remain at 1st column even if the column is dragged to some other position.
Here is what i did: Inherited from QAbstractItemDelegate to create a GItemDelegate whose paint method has something like this
Code:
QTreeView *t_view
= qobject_cast<QTreeView
*>
(parent
());
if(t_view)
if(t_view->header()->visualIndex(index.column()) == 0){
value = model->data(index, Qt::DecorationRole);
pixmap = decoration(opt, value);
pixmapRect
= (pixmap.
isNull() ?
QRect(0,
0,
0,
0):QRect(QPoint(0,
0), option.
decorationSize));
}
New problem: Documentation for header()->visualIndex say that
Quote:
Hidden sections still have valid visual indexes
Hence, if first column is hidden icon is not visible.
-----------------------------------------------------------
So the question is how to (quickly) determine the first visible column of QTreeView in GItemDelegate.
Thanks
Re: How to dispay an icon in the first column of QTreeView
I suggest iterating over all sections from 0 to header()->count() and check for each section wether it's visible. If it is visible, show the icon. If it is not visible, go on with the next section.