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 generate an event to ESC (Escape), F1 and such keys.
QtWS25 Last Chance

How to generate an event to ESC (Escape), F1 and such keys.

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 16.5k 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.
  • M Offline
    M Offline
    marcus_cps
    wrote on 6 Sept 2010, 20:02 last edited by
    #4

    [quote author="dfaure" date="1283803055"][replied in the embedded forum][/quote]

    Lets continue here. The other thread is going to fall.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      marcus_cps
      wrote on 6 Sept 2010, 20:02 last edited by
      #5

      Here is dfaure message that was posted in the other thread:

      [quote] At first sight I don’t see anything wrong with the code you posted, the problem must be elsewhere. What type of widget is “this”?
      One idea could it be that the Esc key closes the dialog, and that F1 triggers some help action…

      In fact between posting a QKeyEvent and getting a keyEventPressed, many things can happen:

      • shortcut handling (if a widget accepts the ShortcutOverride event for instance; or if a QAction exists with this key)
      • event filters

      Please give more information. Ideally extracting a standalone testcase, that’s the easier to look at smile. [/quote]

      [cleaned up formatting and deleted the other thread = Alexandra]

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marcus_cps
        wrote on 6 Sept 2010, 20:05 last edited by
        #6

        The handler from LIRC (Linux InfraRed client or something like this) is a QObject derived class.

        All the other windows are QWidgets and I'm trying to receive Keypress events in them.

        I'm doind a few test on monday. Now I'm in a holliday! :D
        Thanks. I'll be in touch.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kkrzewniak
          wrote on 6 Sept 2010, 21:19 last edited by
          #7

          Am I getting something wrong here or is your “key interpreting” object posting events to itself.
          @void QCoreApplication::postEvent ( QObject * receiver, QEvent * event )@
          If that is the case than I think You should check this objects keyPressEvent, maybe those specific events get accepted by this object and their propagation stops there.

          Me, Grimlock, not "nice dino". ME BASH BRAINS!

          1 Reply Last reply
          0
          • M Offline
            M Offline
            marcus_cps
            wrote on 6 Sept 2010, 21:23 last edited by
            #8

            This class is something like a keyboard driver, however not to a keyboard, it is to the IR Remote Control.
            It recieves the Remote Control keypress through a socket. And that code would translate the string information about the pressed key to a QT key event.
            My goal is to use this class to generate key events to the entire application.

            Notice that I'm generating QKeyEvents and using a signal to notify any registered slot about that too.
            That's an workaround, I really want to take this signal/slots approach out and keep using the QKeyEvent part only.

            I believe this is how I generate key events to the entire application, so the QT framework itself decides which Widget is going to receive the event.

            @
            void QCoreApplication::postEvent ( QObject * receiver, QEvent * event )
            @

            Is this wrong?
            Maybe we've found the mistake.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              marcus_cps
              wrote on 6 Sept 2010, 21:32 last edited by
              #9

              Maybe I'm wrong!
              Now I noticed the first parameter is the RECEIVER of the Event, not the GENERATOR of the event.
              Have to read a little about that.
              Does anyone know something about how to generate events to the entire application (letting QT decide who is going to receive the event)?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kkrzewniak
                wrote on 6 Sept 2010, 21:46 last edited by
                #10

                Just a wild guess but I would try using @QApplication::postEvent(qApp, event);@ instead of @QApplication::postEvent(this, event);@ as qApp is a pointer to the object representing the current QApplication instance. But I don't relay know if that'll result in the event being passed to the active widget I don't know.

                Me, Grimlock, not "nice dino". ME BASH BRAINS!

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  marcus_cps
                  wrote on 6 Sept 2010, 22:10 last edited by
                  #11

                  I'll give a shot on Monday. Maybe we are lucky this time. Will post news asap.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dfaure
                    wrote on 1 Oct 2010, 23:08 last edited by
                    #12

                    kkrzewniak: posting events to qApp will only post the event to qApp, not to the active widget ;)

                    If one wants to send events to the active widget, then sending them to QApplication::focusWidget() might help.

                    David Faure (david.faure@kdab.com)
                    KDE/Qt Senior Software Engineer
                    KDAB - Qt Experts - Platform-independent software solutions

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      marcus_cps
                      wrote on 2 Oct 2010, 19:51 last edited by
                      #13

                      Great idea.
                      I've been trying to find some time to test the last suggestion kkrzewniak made.
                      I'll do it ASAP and will try this too.
                      It sounds like will work.

                      Thanks very much for your help.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        marcus_cps
                        wrote on 17 Dec 2010, 16:46 last edited by
                        #14

                        That worked.

                        I had to make a lot of changes to fit with this.
                        But now, that's all fine!

                        Thanks so much for your help guys.

                        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