[Qt-interest] Mouse events inside item view delegates
Neville Dastur
qt at dastur.me.uk
Mon Aug 23 00:35:17 CEST 2010
Thank you Andre. I had, but could see how it would help, the 4.6
documentation is sparse, to say the least. Reading the 4.7 docs (which
does apply to 4.6.3) it states that even if an editor event does not
occur, mouse events are still sent to the member function.
For anyone else, this snippet achieves the desired effect:
virtual bool editorEvent (QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option, const
QModelIndex &index ) {
if(event->type() == QEvent::MouseButtonRelease) {
QMouseEvent *me = (QMouseEvent*)event;
if (me) {
qDebug() << "::editorEvent() mouse release click
position = " << (me->pos() - option.rect.topLeft());
}
} else {
event->ignore();
}
}
On 22/08/10 09:43, Andre Somers wrote:
> Op 22-8-2010 0:16, Neville Dastur schreef:
>
>> Hi
>>
>> I don't know if someone can help me. I have a QTreeView and for one of
>> the columns I set a custom delegate. This delegate paints a number of
>> icons in a row, within that column, representing buttons.
>>
>> Now I want to be able to detect a mouse click on my custom delegate and
>> determine the position within the item so that I know which item has
>> been "clicked"
>>
>> For the life of me a and plenty of searching I can't find out how to do
>> this.
>>
>> From within the on_treeView_clicked(QModelIndex *i) slot I can find a
>> way of getting mouse coordinates relative to the item and the
>> MouseRelease event doesn't seem to get called at all.
>>
> Did you look at letting the delegate handle the mouse interaction?
> See QAbstractItemDelegate::editorEvent
>
> André
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list