5

Qt offers this with QGuiApplication::keyboardModifiers(). What is the QML way?

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103

1 Answers1

3

In QML there exists the KeyEvent (see here for further details) that has a property named modifers.
It contains a bitwise combination of the available modifiers.

It follows an example taken directly from the documentation above mentioned:

Item {
    focus: true
    Keys.onPressed: {
        if ((event.key == Qt.Key_Enter) && (event.modifiers & Qt.ShiftModifier))
            doSomething();
    }
}

For the complete list of the available modifiers, please refer to the official documentation.

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • Thats fine but I want to query the cached modifiers outsiden an event handler. – ManuelSchneid3r Feb 10 '16 at 23:10
  • 3
    Oh, oK, got it. Well, what do you have in place of `QGuiApplication::keyboardModifiers`? The same static method. Export it from the C++ layer to the QML one and that's all. Why can't you do that? – skypjack Feb 11 '16 at 06:47