Keyboard shortcuts - detecting key press and release



  • I'm wondering whether it's possible to use Qt's keyboard shortcut facilities (either QShortcut or QAction) to fire events depending on the up/down state of keys? I have a camera view where the 3D camera is controlled by the WASD keys and I'd much rather have the user be able to to set the key bindings in the same window as they would adjust the rest of the application keyboard shortcuts, rather than having to hard-code things or deal with QKeyEvents in the view widget manually.

    I have experimented with checkable QActions and these are almost what I want - if I add an action to a QWidget, the triggered(bool state) signal can be connected to a stateful(bool state) slot or a stateless() slot, depending on the type of shortcut I want (true/false vs. one-off). However, the checked state of the QAction is changed only when I re-press the keyboard shortcut, which isn't great for controlling camera movement. Is there any possible way to utilise this setup where the state bool of the signal reacts to the up/down state of the key combination?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.