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. Send KeyEvent to hidden Object
QtWS25 Last Chance

Send KeyEvent to hidden Object

Scheduled Pinned Locked Moved Unsolved General and Desktop
keyeventobjecthidefocus
9 Posts 2 Posters 4.1k Views
  • 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    Hi

    I need to send KeyEvents to hidden objects.
    For shown objects, this works perfectly when I set the focus (setFocus()) to the object that should receive the event and then the key event is distributed using the normal event handler - works as expected.
    According documentation, this is not possible for hidden objects, and that's exactly what I stumbled across. (Doc 4.6: Be aware that if the widget is hidden, it will not accept focus until it is shown.)

    Any idea how I can make a hidden object accepting the keyEvent?

    Thanks
    McL

    raven-worxR 1 Reply Last reply
    0
    • McLionM McLion

      Hi

      I need to send KeyEvents to hidden objects.
      For shown objects, this works perfectly when I set the focus (setFocus()) to the object that should receive the event and then the key event is distributed using the normal event handler - works as expected.
      According documentation, this is not possible for hidden objects, and that's exactly what I stumbled across. (Doc 4.6: Be aware that if the widget is hidden, it will not accept focus until it is shown.)

      Any idea how I can make a hidden object accepting the keyEvent?

      Thanks
      McL

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @McLion
      simply you don't, since this is given by design.

      But what are you trying to achieve anyway? Why does a hidden widget need to receive an input event?!
      This sounds like a design issue in your code.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by McLion
        #3

        We are using multiple webView's to create a very fast and responsive GUI for an embedded system. The GUI's are preloaded and are hidden/shown.
        There are cases where a currently still hidden GUI should receive a keyevent before it is shown, so that it is already prepared before the show applies.
        Of course, if i show it first and then send the key, this works. However, it does not look nice.

        raven-worxR 1 Reply Last reply
        0
        • McLionM McLion

          We are using multiple webView's to create a very fast and responsive GUI for an embedded system. The GUI's are preloaded and are hidden/shown.
          There are cases where a currently still hidden GUI should receive a keyevent before it is shown, so that it is already prepared before the show applies.
          Of course, if i show it first and then send the key, this works. However, it does not look nice.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @McLion
          how are you exactly sending the key events?
          Because actually hidden widgets can also receive key events. The focus is just necessary for the application to determine to which widget the input event should be send.

          Unless the WebView has some internal check if it's visible or if it already has been rendered etc.

          But install an event filter on the hidden webview widget and check if the key event is received.

          But as i said it should work (at least until to this point)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by
            #5

            For shown objects, the Focus is set to the respective obj and then
            the key event (generated from a serial input) is sent like this:

            QKeyEvent keyPress(QEvent::KeyPress, SysKeyCode, Qt::NoModifier);
            QApplication::sendEvent(ActWidget, &keyPress);
            QKeyEvent keyRelease(QEvent::KeyRelease, SysKeyCode, Qt::NoModifier);
            QApplication::sendEvent(ActWidget, &keyRelease); }
            

            Is there a way to post the key event directly to an object instead of sending it to the application event handler?

            raven-worxR 1 Reply Last reply
            0
            • McLionM McLion

              For shown objects, the Focus is set to the respective obj and then
              the key event (generated from a serial input) is sent like this:

              QKeyEvent keyPress(QEvent::KeyPress, SysKeyCode, Qt::NoModifier);
              QApplication::sendEvent(ActWidget, &keyPress);
              QKeyEvent keyRelease(QEvent::KeyRelease, SysKeyCode, Qt::NoModifier);
              QApplication::sendEvent(ActWidget, &keyRelease); }
              

              Is there a way to post the key event directly to an object instead of sending it to the application event handler?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @McLion
              yes and this works also for hidden widgets. As i said, give it a try installing an event filter on that widget.
              It may be that the webview widget internally does some additional checking if it is visible idk.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1
              • McLionM Offline
                McLionM Offline
                McLion
                wrote on last edited by
                #7

                OK ... I'm not sure where to add this event filter.
                I have an event filter in class MyApplication where I do some mouse/touch handling and forward unhandled events to QApplication.

                The webView's I use are not subclassed, I'm creating them as needed in code at runtime in my MainWindow class.

                Sorry for my missing knowledge ... where do I add this eventfilter for a specifc webView?
                Thanks

                raven-worxR 1 Reply Last reply
                0
                • McLionM McLion

                  OK ... I'm not sure where to add this event filter.
                  I have an event filter in class MyApplication where I do some mouse/touch handling and forward unhandled events to QApplication.

                  The webView's I use are not subclassed, I'm creating them as needed in code at runtime in my MainWindow class.

                  Sorry for my missing knowledge ... where do I add this eventfilter for a specifc webView?
                  Thanks

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by raven-worx
                  #8

                  @McLion said in Send KeyEvent to hidden Object:

                  where do I add this eventfilter for a specifc webView?

                  on the webview widget (QObject::installEventFilter())

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  3
                  • McLionM Offline
                    McLionM Offline
                    McLion
                    wrote on last edited by
                    #9

                    I now have an eventfilter on every of my (16) webView.
                    I added some debug on the MyApp notify and in the new eventfilter.
                    I can see that myApp gets every keypress (first) and the installed eventfilter on the webView's gets the keypress only if any of the webView is shown.

                    I'm not sure how to proceed or how this helps in forwarding the event to a specific webView since the event is not getting to the eventfilter if a webView is not active.

                    How about catching the event in MyApp notify and somehow posting it to a specific webView?

                    Thanks for your help.

                    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