How to detect when icon clicked in item delegate ?

  • Hi
    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 ?

  • You should reimplement the editorEvent() virtual method from [[doc:QAbstractItemDelegate]]. From the documentation:
    [quote]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.[/quote]
    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.