Dynamically created Menu is triggered by space key
Solved
QML and Qt Quick
-
Hi,
When I have a menu which is created on demand, after first request - it can be triggered by space key press what is completely undesired.
Here is example code:import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Window 2.2 ApplicationWindow { visible: true property Menu menu: null Button { text: "get menu" onClicked: { if (!menu) menu = menuComp.createObject(this) menu.open() } } Component { id: menuComp Menu { width: 200; height: 400 MenuItem { text: "action 1" } MenuItem { text: "action 2" } } } }
Do You think it is a bug or a kind of my misusing?
-
I think it's because the menu gets the keyboard focus when it's created.
-
The following seems to work:
onClicked: { if (!menu) menu = menuComp.createObject(this) menu.open() menu.focus = false }
-
@Wieland
Works, but only first time...
When menu is ignored by pressingESC
or clicking outside, problem comes back, but when menu item is selected menu doesn't react on space key. -
Mhh, maybe this?
onClicked: { if (!menu) menu = menuComp.createObject(this) menu.open() focus = false // remove focus from the button on click }