1

Question/Issue

I tried reimplementing the event method in a custom delegate to handle clicks. The delegate is used to render table cells in a table view. However, I do not get any events for the delegate (the method is never called according to the debuger). Is there anything special I need to do so my delegate can track events (in particular mouse entering/exiting, clicks)?

Context

I would like to create my own data representation for table cells. The functionality should be close to a button, but slightly different. I read that the two options for implementing buttons in table are either setting a cell widget which supposedly has a high performance cost (I did not quite understand why) or using a delegate.

Since I want different behaviour than that of a button, and for the speed myth I decided to go with a delegate.

ted
  • 4,791
  • 5
  • 38
  • 84
  • If you need to handle mouse clicks, handle signals/events of the object the event has actually occurred on. If your delegate class provides widget for cells representation, handle events on that very widgets and not in the delegate class. – vahancho May 07 '15 at 13:55
  • @vahancho my delegate just draws a QPixmap with `QPainter.drawPixmap`, I guess there is nothing that should eat the events. The question is, do I need to enable events for my delegate somehow, or is there any reason why a delegate should not receive events? – ted May 07 '15 at 14:06
  • If your delegate is just for painting, than you might use `QAbstractItemView::clicked()` signal of your table view to handle mouse clicks on it. No need to deal with events at all. – vahancho May 07 '15 at 14:11
  • I just inherit `QAbstractItemDelegate`, and actually I would like to handle mouse down/up and mouse over/ mouse out events. Also even if it turns out that there are `buttonDown/up`, `mouseEnter/leave` methods, I would still like to figure out why my `event` function does not get called at all. – ted May 07 '15 at 14:38
  • `QAbstractItemDelegate` is a `QObject`. It cannot accept and handle GUI events. Again - handle GUI events in QWidget based classes, which is, for instance, your table view. – vahancho May 07 '15 at 14:44

1 Answers1

1

Mouse events are send to the QAbstractItemDelegate::editorEvent() method, even if they don't start editing of the item.

See: http://doc.qt.io/qt-5/qabstractitemdelegate.html#editorEvent

titusjan
  • 5,376
  • 2
  • 24
  • 43