Reputation: 111
I have some buttons and associated functions in my qml code, I want one button to be triggered when the enter key is pressed. All the buttons are handled by onClick event, ie, when the button is clicked my mouse,it executes the associated functions. I want to execute the click when the enter key is pressed
Upvotes: 7
Views: 6005
Reputation: 3976
You can react to different signals:
Button {
id: _button
text: "Button"
function activate() { console.debug("Button activated"); }
onClicked: _button.activate()
Keys.onReturnPressed: _button.activate() // Enter key
Keys.onEnterPressed: _button.activate() // Numpad enter key
}
Your button needs the focus to be notified about the key-press. If you want one specific button to have the focus by default, just add in the button
focus: true
Upvotes: 7