Hello

I've been trying to add a basic keyboard input handler to my mainwindow. The mainwindow has a few Qlabels and pushbuttons, nothing fancy.

I've tried adding the following code:

mainwindow.h
Qt Code:
  1. protected:
  2. void keyPressEvent(QKeyEvent *event);
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. void MainWindow::keyPressEvent(QKeyEvent *event)
  2. {
  3. std::cout << "pressed";
  4. }
To copy to clipboard, switch view to plain text mode 

But nothing happens when I press a key. I think there's something very simple that I'm missing, but I just can't figure it out. Trust me I've googled quite a bit on the topic but got nowhere. Any help would be greatly appreciated. Thanks.