I have a class based on QWidget as such:
class tetris_canvas : public QWidget { Q_OBJECT public: tetris_canvas(QWidget * parent = 0); ~tetris_canvas(); protected: void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); };
Then I have a main_window class:
class main_window : public QWidget { Q_OBJECT public: main_window(QWidget* parent = 0, Qt::WFlags flags = 0); ~main_window(); protected: void keyPressEvent(QKeyEvent * event); };
My question is: how do I get keyPressEvent in my tetris_canvas widget to respond to a keystroke?
I draw inside this canvas, and I need to respond to keystrokes so that the user can interact with things on this canvas.
The widget is added to the QGridLayout in the ctor or my main_window .
source share