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. Why key press events of some keys are not sent to notify()
Forum Updated to NodeBB v4.3 + New Features

Why key press events of some keys are not sent to notify()

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.6k 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.
  • xiazeyiX Offline
    xiazeyiX Offline
    xiazeyi
    wrote on last edited by xiazeyi
    #1

    I am working on a Qt gui application that defines its own application class inheriting from QApplication and overrides nofity() method. I found key press events of Ctrl + L and some other keys are not sent to this method and key release events work well, but everything works correctly if I create a clean application with Qt Creator. I want to find out the root cause of this problem, but I do not have any idea about how to make it.
    Does Qt has any mechanism to filter event out before sending to notify()? Or any solution to find out the root cause?

    jsulmJ 1 Reply Last reply
    0
    • xiazeyiX xiazeyi

      I am working on a Qt gui application that defines its own application class inheriting from QApplication and overrides nofity() method. I found key press events of Ctrl + L and some other keys are not sent to this method and key release events work well, but everything works correctly if I create a clean application with Qt Creator. I want to find out the root cause of this problem, but I do not have any idea about how to make it.
      Does Qt has any mechanism to filter event out before sending to notify()? Or any solution to find out the root cause?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @xiazeyi Are you sure Ctrl-L is not sent? Can you show the notify() method?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      xiazeyiX 1 Reply Last reply
      0
      • jsulmJ jsulm

        @xiazeyi Are you sure Ctrl-L is not sent? Can you show the notify() method?

        xiazeyiX Offline
        xiazeyiX Offline
        xiazeyi
        wrote on last edited by
        #3

        @jsulm With the following code, only key release event is printed for Ctrl+L

        bool MyQtApplication::notify(QObject* receiver, QEvent* event)
        {
            try
            { 
                if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
                {
                    auto keyEvent = dynamic_cast<QKeyEvent*>(event);
                    std::cout << "type: " << keyEvent->type() << "; modifiers: " << keyEvent->modifiers() << "; key: " << keyEvent->key() << std::endl;
                }
                return QApplication::notify(receiver, event);
            }
            catch(const std::exception& ex)
            { 
                std::cout << "unhandled exception: " << ex.what() << std::endl;
            }
            catch(...)
            { 
                std::cout << "unhandled exception occured" << std::endl;
            }
            
            return false;
        }
        
        JonBJ 1 Reply Last reply
        0
        • xiazeyiX xiazeyi

          @jsulm With the following code, only key release event is printed for Ctrl+L

          bool MyQtApplication::notify(QObject* receiver, QEvent* event)
          {
              try
              { 
                  if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
                  {
                      auto keyEvent = dynamic_cast<QKeyEvent*>(event);
                      std::cout << "type: " << keyEvent->type() << "; modifiers: " << keyEvent->modifiers() << "; key: " << keyEvent->key() << std::endl;
                  }
                  return QApplication::notify(receiver, event);
              }
              catch(const std::exception& ex)
              { 
                  std::cout << "unhandled exception: " << ex.what() << std::endl;
              }
              catch(...)
              { 
                  std::cout << "unhandled exception occured" << std::endl;
              }
              
              return false;
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @xiazeyi
          Verify whether you are receiving a QEvent::ShortcutOverride instead of QEvent::KeyPress? Also see https://forum.qt.io/topic/34583/solved-qwidget-eventfilter-not-catching-key-combinations

          xiazeyiX 1 Reply Last reply
          3
          • JonBJ JonB

            @xiazeyi
            Verify whether you are receiving a QEvent::ShortcutOverride instead of QEvent::KeyPress? Also see https://forum.qt.io/topic/34583/solved-qwidget-eventfilter-not-catching-key-combinations

            xiazeyiX Offline
            xiazeyiX Offline
            xiazeyi
            wrote on last edited by
            #5

            @JNBarchan It works. So it means Ctrl+L is defined as a shortcut in the application, and according to this clue I have found the code to set Ctrl+L as shortcut of an action.
            Thanks!

            JonBJ 1 Reply Last reply
            0
            • xiazeyiX xiazeyi

              @JNBarchan It works. So it means Ctrl+L is defined as a shortcut in the application, and according to this clue I have found the code to set Ctrl+L as shortcut of an action.
              Thanks!

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @xiazeyi
              Yeah, I know, I'm a genius... ;-) I've never even seen a keypress event....

              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