March 20, 2012

umen242 umen242
Lab Rat
198 posts

How to detect when icon clicked in item delegate ?


i have QTableView item delegate , which there i construct text and 2 icons one for delete the table row and one to do some other action .
my question is how to detect and trigger function when my mouse is click on one of the icons in the item delegate ?
do i need to post code ?

1 reply

March 20, 2012

Andre Andre
Robot Herder
6663 posts

You should reimplement the editorEvent() virtual method from QAbstractItemDelegate. From the documentation:

Mouse events are sent to editorEvent() even if they don’t start editing of the item. This can, for instance, be useful if you wish to open a context menu when the right mouse button is pressed on an item.

So, you can handle mouse events from this method. It is up to you to determine if a click is on an icon or not.

For communication of the event, I would give the delegate one or more signals (that include a QModelIndex as an argument) that communicate the triggering of the event.

  ‹‹ QGLPixelbuffer in threads is blocking      Implementing multi-selection in QTextEdit ››

You must log in to post a reply. Not a member yet? Register here!