I would like to catch the Space key in my app.
The header:

Qt Code:
  1. #pragma once
  2. #include <QWidget>
  3. #include <iitem.hpp>
  4. #include <ui_invpg.h>
  5.  
  6.  
  7. class InvPage : public QWidget
  8. {
  9. Q_OBJECT
  10.  
  11. public :
  12.  
  13. InvPage();
  14. virtual ~InvPage();
  15.  
  16. void clear();
  17. void ClearSel();
  18. void MakeList();
  19. void MakeInv();
  20. void LoadData();
  21.  
  22. IItem *theitem;
  23. bool addit;
  24.  
  25. protected :
  26.  
  27. virtual void keyPressEvent( QKeyEvent *event );
  28.  
  29. private :
  30.  
  31. Ui::InvPage ui;
  32.  
  33. private slots :
  34.  
  35. void ItemClicked( QListWidgetItem *item );
  36. };
To copy to clipboard, switch view to plain text mode 

The ctor contains only ui.setupUi(this). The (current) implementation should test whether the handler works:

Qt Code:
  1. #include <QWidget>
  2. #include <QKeyEvent>
  3. #include <myapp.hpp>
  4. #include <myframe.hpp>
  5. #include <invpage.hpp>
  6. #include <iitem.hpp>
  7. #include <data.hpp>
  8.  
  9.  
  10. void InvPage::keyPressEvent( QKeyEvent *event )
  11. {
  12. if( event->key() == Qt::Key_Space )
  13. {
  14. char str[40];
  15.  
  16. sprintf(str,"%s",(addit ? "addit = true" : "addit = false"));
  17. TheApp->frame->statusBar()->showMessage(str,2000);
  18. }
  19.  
  20. QWidget::keyPressEvent(event);
  21. }
To copy to clipboard, switch view to plain text mode 

It does not work. Putting a breakpoint at the "if" shows that the handler isn't called at all. What kind of blunder am I making? (Note: the statusbar works fine.)