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
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));
}
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));
}
To copy to clipboard, switch view to plain text mode
New problem: Documentation for header()->visualIndex say that
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
Bookmarks