Search code examples
qmlqtquickcontrols2

How are the default keyboard interactions of QtQuick Controls 2 specified?


The controls in QtQuick.Controls 2 have some keyboard responses by default.

For example, the ComboBox will change selection in response to the up & down keys, and the box' Popup will open if the user presses spacebar. I haven't been able to find where this behavior was specified, and I need to change it.

At the moment, I need the return key to do what the spacebar is doing. But of course being able to customize these key interactions is generally useful.


Solution

  • There is no generic way to configure Qt Quick Controls 2 to do all the actions everywhere with the return key, that it would do with the spacebar key. However, you can attach a Keys handler and apply the desired actions yourself:

    ComboBox {
        id: comboBox
        Keys.onReturnPressed: comboBox.popup.open()
    }