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. keyPressEvent suddenly not firing
QtWS25 Last Chance

keyPressEvent suddenly not firing

Scheduled Pinned Locked Moved General and Desktop
qt 5.4.1msvc2013
9 Posts 2 Posters 3.4k 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.
  • B Offline
    B Offline
    Bear35645
    wrote on 15 Sept 2015, 19:13 last edited by
    #1

    I have a program I have been working on for over a year. I have multiple forms, one being the Main Window. I made one change to the keyPressEvent method on one of the forms derived from QDialog and now all of a sudden the only form the keypress event works on is the main. All other forms it never fires. The only thing I changed was adding another case to my switch statement to handle a different keypress. Why this would break the keyPress event on all other forms except the main window is beyond me.

    I am grabbing the keyboard in the constructor for the form.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bear35645
      wrote on 15 Sept 2015, 19:28 last edited by
      #2

      Update. When I created an object for one of my forms, I passed in "this" from the Main Window as the parent object. For some reason this breaks the keypress event in the child form.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 15 Sept 2015, 19:32 last edited by
        #3

        What key press event handling did you modify ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply 15 Sept 2015, 19:35
        0
        • S SGaist
          15 Sept 2015, 19:32

          What key press event handling did you modify ?

          B Offline
          B Offline
          Bear35645
          wrote on 15 Sept 2015, 19:35 last edited by Bear35645
          #4

          @SGaist I modified the keyPressEvent handler in the on of my Dialog forms (not the main window). I wanted to add handling when the user presses the 8 key. In my reply I noted that I did also add passing "this" from the main window as the parent object of the dialog when I created the dialog object. When I removed that it started working again.

          The goal is when the users presses the 8 key, to close the Dialog and pass the key press back to the main window.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 15 Sept 2015, 19:46 last edited by SGaist
            #5

            In that case, shouldn't you rather handle that directly in the main window and use it as a filter on your dialog ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            B 1 Reply Last reply 15 Sept 2015, 20:24
            0
            • S SGaist
              15 Sept 2015, 19:46

              In that case, shouldn't you rather handle that directly in the main window and use it as a filter on your dialog ?

              B Offline
              B Offline
              Bear35645
              wrote on 15 Sept 2015, 20:24 last edited by
              #6

              @SGaist I don't understand the question, but here is the situation. The target system has 9 total keys. 1-8 and T. On most screens these keys have the same behavior. However, the 8 key on all screens but the Main Window causes the current screen to close then the Main Window needs to react as if it had focus with the 8 key was pressed.

              I just added code to search through the QWindowList returned by QApplication::topLevelWindows to find a pointer to the Main Window. I then use that pointer in the QApplication::sendEvent to send the 8 key press to it.

              What I am wondering is if it would work the same way if I do not call event->accept() when the 8 key is pressed and just close the current window?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 15 Sept 2015, 20:32 last edited by
                #7

                I meant Event Filters.

                So your MainWindow would be doing all the handling of the 8 key itself

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                B 1 Reply Last reply 15 Sept 2015, 20:49
                0
                • S SGaist
                  15 Sept 2015, 20:32

                  I meant Event Filters.

                  So your MainWindow would be doing all the handling of the 8 key itself

                  B Offline
                  B Offline
                  Bear35645
                  wrote on 15 Sept 2015, 20:49 last edited by
                  #8

                  @SGaist Not really because the current window has to close before the main window handles the 8 key. All the other windows are started using exec() method from the main screen.

                  For example I create password screen object (a). I call a.exec() to actually show the screen.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 15 Sept 2015, 22:04 last edited by
                    #9

                    Well, that would be part of the logic of the filter: first step, close the dialog, second handle 8.

                    In any case, your idea of not calling accept on the event should result it in being forward to your MainWindow

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    1/9

                    15 Sept 2015, 19:13

                    • Login

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