Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.1.0
-
None
Description
Description:
When opening and immediately closing a context menu by doing two right-clicks without moving the mouse pointer in between, Qt5 currently selects the first item of the context menu.
Expected behavior:
I would expect that the second mouse click simply closes the menu without activating an item.
Actual behavior:
The first item of the context menu is activated, probably without user intention.
Regression:
I think this is a usability issue since many users will probably activate items in the context menu without intending so. I examined the behavior on different systems (Windows 7, OSX, other Linux Desktops), they all simply close a context menu on the second mouse click.
Steps to reproduce:
- build a sample project containing a widget that handles
the context-menu event (see code-snippet nelow) - position mouse in this widget and hold the mouse still,
i.e. the mouse pointer shall not move - right click on the mouse to open a context menu
- right click again
=> the first action of the menu is activated
Example codesnippet:
void Widget::contextMenuEvent (QContextMenuEvent *event)
{
QPoint where (event->globalPos ());
QMenu menu;
... // build menu contents
QAction *selectedAction = menu.exec (where);
...
}
Workaround / possible solution:
I would suggest to translate the given position for the menu by 1 pixel in x and y direction and opening the menu at the translated position. So the mouse pointer is not hovering the first menu item.