c++ - Qt: open context menu on mouse press -
c++ - Qt: open context menu on mouse press -
i'm trying alter default behavior of context menus: instead of opening on release event of right mouse button, want open on press event, , it's actions triggered on release event). on 1 widget overload mousepressevent() , fire custom contextmenu event, want global context menus of program...
any ideas?
thanks.
i trying implement widget base of operations on top of qwidget custom way handle context menu suit needs when realize using actionscontextmenu policy actions straight own widget behavior expecting. (qt 4.6.2 & 4.7 on linux, didn't seek on windows yet don't know why behavior should different).
is policy can utilize ? if don't really need external menus, i'll suggest go solution.
otherwise have create own widget base of operations custom qmenu member. should utilize qt::preventcontextmenu policy guarantee right click end in void mousepressevent(qmouseevent *event) of widget. in event handler create sure show menu. in menu re-implement void mousereleaseevent( qmouseevent *event) if don't trigger current action your-self mouse position (in event) , qaction* actionat( const qpoint & pt) const. careful void mousereleaseevent( qmouseevent *event) of qmenu re-implemented qwidget , may stuff want preserve !
edit it's kind of sad behavior seems different by design on windows void qmenu::mousereleaseevent(qmouseevent *e) following:
extracted form qmenu.cpp, qt 4.6.2 sdk
#if defined(q_ws_win) //on windows context menus can activated right button if (e->button() == qt::leftbutton || d->topcausedwidget() == 0) #endif d->activateaction(action, qaction::trigger); i don't know topcausedwidget() in life it's kind of explicit left button release trigger current action ...
one simple solution re-implement qmenu line commented ...
c++ qt4 contextmenu
Comments
Post a Comment