Update listview model from delegate paint event
Solved
General and Desktop
-
I have a QListView where I custom draw the iconview using a delegate. I need to save a QRect containing the coordinates of part of an iconview item that can be used later to translate coordinates from a mouse click event on the thumbnail. I am having difficulties overcoming the const status.
Here is a code snippet from the delegate:
void ThumbViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { // define iconRect coordinates // save iconRect to model index.model()->setData(index, iconRect, Qt::UserRole+5); // this generates error // qt cannot convert 'this' pointer from 'const QAbstractItemModel' to 'QAbstractItemModel &' }
How do I update the model?
Thanks in advance.
Rory -
Hi,
The paint event is not the place to do it at all, you should rather take a look at the mouse events related methods of QListView.
-
You're welcome !
QAbstractItemView::visualRect should give you that information.