Answer the question
In order to leave comments, you need to log in
How to bind a key press and a Button press?
Small sketch:
Button {
id: b3
text: "."
}
Shortcut {
sequence: "Esc"
onActivated: b3.clicked()
}
Answer the question
In order to leave comments, you need to log in
So?
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;
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question