Button {
id: b3
text: "."
}
Shortcut {
sequence: "Esc"
onActivated: b3.clicked()
}
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Item {
anchors.fill: parent
focus: true
Button {
id: mainButton
anchors.centerIn: parent
text: "button"
onClicked: console.log("clicked")
}
Keys.onPressed: {
if (event.key === Qt.Key_Escape) {
// Do something when key pressed
mainButton.clicked();
event.accepted = true;
}
}
Keys.onReleased: {
if (event.key === Qt.Key_Escape) {
// Do something else when key released
event.accepted = true;
}
}
}
}