I am writing to Qt and it became necessary to override the keyPressEvent function. I do it like this:

void glass::keyPressEvent(QKeyEvent *) { // тело функции } 

where glass is the class name. However, the application does not respond to keystrokes, but it is worth changing the class name to QWidget, as everything starts to work. What can be wrong?

Class declaration:

 class glass : public QWidget { public: // Остальные функции protected: void keyPressEvent(QKeyEvent*); private: }; 
  • one
    show glass class declaration - nanotexnik
  • one
    Good day! The documentation says that in order to properly handle the key press event in your widget, it is very important to call the base class method within your implementation. - progzdeveloper
  • it would be nice to add virtual in the declaration keyPressEvent - dzukp

1 answer 1

 void glass::keyPressEvent(QKeyEvent *event) { // // ... // QWidget::keyPressEvent(event); }