Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to check if QAction shortcut is released?

How to check if QAction shortcut is released?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 612 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alhasni
    wrote on last edited by Alhasni
    #1

    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?

    Pl45m4P 1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      2
      • A Alhasni

        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?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @Alhasni

        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


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved