Search code examples
qt5keypress

In Qt how can I know which modifier keys are pressed without overriding the key press and release event functions


I am writing a UI manager where, when you ctrl-alt-rclick a widget, it allows you to edit the widget.

I have implemented key press and release functions in the top level window so as to be able to detect the state of the ctrl and alt keys. However it is very flaky as if another window or dialog gets the focus, the key press events go there instead of to my event listeners.

Every other GUI toolkit I have ever met, and every single Window manager system I have ever met, allow you to check the state of keys at any time, rather than rely on listening to key press/release events.

I have searched the Qt documentation in depth, but cannot find any functionality that would allow me to simply check if a specific key is being held down at any time.

In Qt, how can I detect the state of keyboard keys without monitoring events?


Solution

  • Are you looking for [static] Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers() ?