Qt-interest Archive, August 2006
[model / view ] how to draw the "current index indicator" above the QIcon of a QModelIndex ?
Message 1 in thread
Hi all !
In short :
How can I obtain the QPen, QColor, etc. used by the QViews (QTreeView...)
when drawing the "selected index's" border ?
In detail :
The "current item" of a view ( QAbstractItemView::currentItem() ) is drawn
usually with a dashed thin rect. The dashed thin rect is drawn only arround
the Qt::DisplayRole of the QModelIndex.
Consequently, when a QModelIndex that has no Qt::DisplayRole is made the
"current item", the dashed rect is no more visible in the view.
In order force a dashed rect to be drawn, I subclassed my QView and redefine
paintEvent with something like :
if(currentIndex().isValid() ) {
gridPen.setStyle(Qt::DotLine);
painter.setPen(aPen);
if(currentIndex().column() == 1) {
rect = visualRect (currentIndex());
painter.drawRect(rect);
}
}
Unfortunately, the QPen I use is not the correct one.
So, back to my question... ;=)
How can I obtain the QPen, QColor, etc.used by the QViews (QTreeView...)
when drawing the "selected index's" border ?
Best -
Nicolas
--
[ signature omitted ]
Message 2 in thread
On 25.08.06 20:21:43, Nicolas Castagne wrote:
> In short :
> How can I obtain the QPen, QColor, etc. used by the QViews (QTreeView...)
> when drawing the "selected index's" border ?
You can't get these from the view.
> In detail :
> The "current item" of a view ( QAbstractItemView::currentItem() ) is drawn
> usually with a dashed thin rect. The dashed thin rect is drawn only arround
> the Qt::DisplayRole of the QModelIndex.
>
> Consequently, when a QModelIndex that has no Qt::DisplayRole is made the
> "current item", the dashed rect is no more visible in the view.
>
> In order force a dashed rect to be drawn, I subclassed my QView and redefine
> paintEvent with something like :
Ouch. Read the chapter about model/view again. Painting of the items in
a table or tree is done by the delegate. The delegate get's the painter,
the index to paint and a bunch of style options (among them brushes and
pens). No need to subclass the view, subclass QItemDelegate and set it
on the standard view.
Andreas
--
[ signature omitted ]