W
W
WTFAYD2017-11-12 20:04:25
User interface
WTFAYD, 2017-11-12 20:04:25

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;
        }
    }
}

However, if you throw several buttons in a Column, then only the first button in the list in the column reacts to keystrokes:
Column {
    Button {
        focus: true
        number: 1
    }
    Button {
        focus: true
        number: 2
    }
    ....
}

Please tell me what is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2017-11-14
@Zifix

And where did you get the idea that the focus will be simultaneously on all buttons?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question