Reputation: 16091
Qt offers this with QGuiApplication::keyboardModifiers(). What is the QML way?
Upvotes: 5
Views: 2201
Reputation: 539
Using Qt 6.5.4, I was not able to check the modifiers property for KeyEvent using the method stated in the documentation.
I was able to check the modifiers property using a simple equality check
Keys.onPressed: (event) =>
{
if (event.modifiers === Qt.ShiftModifier)
{
console.log("Shift modifier active")
}
}
Upvotes: 0
Reputation: 50550
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.
Upvotes: 4