You will not be able to get all the keys in QMainWindow, because QApplication may not be passing them on. To capture all the key events, you need install an event filter on the QApplication instance. Then you can have all the keys pressed, and then eat them, or pass them back.

Example:

Qt Code:
  1. class KeySniffer : public QObject
  2. {
  3. Q_OBJECT
  4. ...
  5. protected:
  6. bool eventFilter(QObject * obj, QEvent * event);
  7. };
  8.  
  9. bool KeySniffer::eventFilter(QObject * obj, QEvent * event)
  10. {
  11. if (event->type() == QEvent::KeyPress) {
  12. QKeyEvent *keyEvent = dynamic_cast<QKeyEvent *>(event);
  13. if(keyEvent)
  14. qDebug() << "Key pressed " << keyEvent->key() << keyEvent->text();
  15. }
  16.  
  17. // standard event processing
  18. return QObject::eventFilter(obj, event);
  19. }
  20.  
  21. MainWindow::MainWindow(QWidget *parent)
  22. : QMainWindow(parent)
  23. {
  24. ...
  25. // Filter installation on QApplication
  26. QApplication::instance()->installEventFilter(new KeySniffer(this));
  27. ...
  28. }
To copy to clipboard, switch view to plain text mode