[Solved] QAction - how to distinguish middle click
-
Hello,
is it possible to distinguish middle mouse click from normal (left) click on QAction in QMenu?
I tried subclassing QAction and reimplementing event(QEvent*) function, but this function is called only once, on Action creation.Thanks for any help.
-
event itself will not help, as it is no UI object. You could subclass QMenu and do it there.
-
Thanks for tip. Will test it and post results.
EDIT: Thanks very much, it worked like charm :-)
If someone want to see the code, there it is (I also subclassed QAction to support middleClicked() signal)
@
void Menu::mouseReleaseEvent(QMouseEvent e)
{
Action act = qobject_cast<Action*> (actionAt(e->pos()));if (!act) { QMenu::mouseReleaseEvent(e); return; } if (e->button() == Qt::LeftButton) { act->trigger(); close(); e->accept(); } else if (e->button() == Qt::MiddleButton) { act->triggerMiddleClick(); close(); e->accept(); }
}
@