Answer the question
In order to leave comments, you need to log in
Why is only one of the buttons responding to keypresses?
Hello!
The task is to make a column of a certain number of buttons (from 1 to 9), each of which responds to pressing the key combination Alt + [button number].
I wrote the following code for the button:
import QtQuick 2.0
Rectangle {
property bool opened: false
property int number: 0
width: 40
height: 20
color: (opened) ? "orange" : "grey"
border.width: 1
focus: true
Text {
anchors.centerIn: parent
text: "Кл. " + number
font.pixelSize: parent.width * 0.3
}
Keys.onPressed: {
if (number <= 9 && number >= 0 &&
event.key == (Qt.Key_0 + number) && (event.modifiers & Qt.AltModifier))
{
opened = (opened) ? false : true;
event.accepted = true;
}
}
}
Column {
Button {
focus: true
number: 1
}
Button {
focus: true
number: 2
}
....
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question