How to check if QAction shortcut is released?
-
So I have an application which, among many other things, has audio input from a microphone. I would like to mute the mic while the user is holding space, and unmute when he releases the space.
I first tried to do that by checking for space key press/release events in the main window, but the problem is that most of the time these functions are not called (because some other widget has focus and receives those inputs I assume).
Using an event filter for the application also doesn't work because then no other widget would receive the space (e.g. QTextEdit widgets).
Next I tried to use a QAction with a space shortcut, which worked nicely when the space is clicked. But I can't figure out how to be notified when the shortcut is released. Is this possible?
If that is not possible, what other option do I have?
-
the other option that you have is to use the event filter and then to check witch widget has the focus and add it to it. like that, you will be able to use the space in 2 places in the very same time...- if this is what are you looking for.
else you can use your own widgets and reimplement on all of them the space key press event/ release and then emit a signal for both cases - then connect the main window and all it's widgets to a slot that is dealing with play/pause
-
Why it has to be the Space-Key? :)
@Alhasni said in How to check if QAction shortcut is released?:
Using an event filter for the application also doesn't work because then no other widget would receive the space (e.g. QTextEdit widgets).
Is it not possible for you to tune the filter, that spaces are passed to input fields, but you still check, on what purpose the user pressed the space-key? (Mute or space in textBox?)
You could check whether focus is inside a TextEdit, if not, mute / unmute your mic
@Alhasni said in How to check if QAction shortcut is released?:
I can't figure out how to be notified when the shortcut is released
The QAction shortcut will do nothing else than triggering the QAction. I think you cant access the shortcut event from a QAction directly (why you should? you have KeyPress / KeyReleaseEvents for this).
The ShortcutContext-Enum might be helpful