How to call contextMenuEvent on Qt::Key_F5? I want to display popup menu on Qt::Key_F5.
How to call contextMenuEvent on Qt::Key_F5? I want to display popup menu on Qt::Key_F5.
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
Well,
You don't need to call contextMenuEvent to display a context menu.
When you catch Qt::Key_F5 in keyPressEvent(), you just have to build a QMenu, and exec it at the cursor's current position ( QCursor:os() )
Maybe there are another ways though ;-)
rajesh (12th January 2007)
Thanks! its working.
But..
I have a QTreeWidget and if any tree item is selected and user pressed F5 key then popup menu should be displyed.
problem is, if tree item is selected and mouse pointer is somewhere else then QCursor::Pos() displaying popup menu at mouse pointer position not tree item position.
how to display popup menu at selected tree item position?
Thanks & Regards
Rajesh
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
I don't think there's a direct method to obtain position of an item...
Maybe this would work : when you select an item by clicking, save the cursor position in a variable...and if you call context menu with the cursor away, then use the saved position (assuming you haven't selected anything else :-) )
You can get the geometry of the current/selected item by QTreeWidget::visualItemRect(). Popup the menu for example at the preferred corner of the item (remember to map the coordinate to the global coordinate system, see QWidget::mapToGlobal()).
J-P Nurmi
rajesh (30th January 2007)
That's the good way![]()
Bookmarks