Improve context menu cursor workaround

- Close menu instead of clicking item, to match behavior of other
  programs

- Now work on all edges of the menu, not just top
This commit is contained in:
miruka 2020-07-10 03:36:16 -04:00
parent d4a0434bd9
commit e2bc0cbd84

View File

@ -27,17 +27,19 @@ Menu {
border.color: theme.controls.menu.border border.color: theme.controls.menu.border
border.width: theme.controls.menu.borderWidth border.width: theme.controls.menu.borderWidth
Item { // Workaround for this: when opening menu at mouse position,
// Workaround for this: when opening the menu at cursor position, // cursor will be in menu's border which doesn't handle clicks
// cursor will be in the menu's border instead of first menu item, TapHandler {
// forcing the user to move the mouse for the click to do anything. gesturePolicy: TapHandler.ReleaseWithinBounds
width: parent.width onTapped: eventPoint => {
height: parent.border.width const pos = eventPoint.position
const border = parent.border.width
TapHandler { if (pos.x <= border || pos.x >= parent.width - border)
gesturePolicy: TapHandler.ReleaseWithinBounds menu.close()
onTapped: if (menu.itemAt(0) && menu.itemAt(0).clicked)
menu.itemAt(0).clicked() if (pos.y <= border || pos.y >= parent.height - border)
menu.close()
} }
} }
} }