Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    keyPressEvent suddenly not firing

    General and Desktop
    qt 5.4.1 msvc2013
    2
    9
    2743
    Loading More Posts
    • 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.
    • Bear35645
      Bear35645 last edited by

      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 Reply Quote 0
      • Bear35645
        Bear35645 last edited by

        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 Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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

          Bear35645 1 Reply Last reply Reply Quote 0
          • Bear35645
            Bear35645 @SGaist last edited by Bear35645

            @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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by SGaist

              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

              Bear35645 1 Reply Last reply Reply Quote 0
              • Bear35645
                Bear35645 @SGaist last edited by

                @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 Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  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

                  Bear35645 1 Reply Last reply Reply Quote 0
                  • Bear35645
                    Bear35645 @SGaist last edited by

                    @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 Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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 Reply Quote 0
                      • First post
                        Last post