Hello forum


I have the following class memeber functions that tries to capture the key press and release events, but none of them is captured.


Qt Code:
  1. class DiagramScene : public QGraphicsScene
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
  7.  
  8. DiagramScene(QMenu *itemMenu, QObject *parent = 0);
  9. QFont font() const
  10. { return myFont; }
  11. QColor textColor() const
  12. { return myTextColor; }
  13. QColor itemColor() const
  14. { return myItemColor; }
  15. QColor lineColor() const
  16. { return myLineColor; }
  17. void setLineColor(const QColor &color);
  18. void setTextColor(const QColor &color);
  19. void setItemColor(const QColor &color);
  20. void setFont(const QFont &font);
  21.  
  22. public slots:
  23. void setMode(Mode mode);
  24. void setItemType(DiagramItem::DiagramType type);
  25. void editorLostFocus(DiagramTextItem *item);
  26.  
  27. signals:
  28. void itemInserted(DiagramItem *item);
  29. void textInserted(QGraphicsTextItem *item);
  30. void itemSelected(QGraphicsItem *item);
  31.  
  32. protected:
  33. void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
  34. void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
  35. void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
  36.  
  37. void keyReleaseEvent(QKeyEvent *event);
  38. void keyPressEvent(QKeyEvent *event);
  39.  
  40. private:
  41. bool isItemChange(int type);
  42.  
  43. DiagramItem::DiagramType myItemType;
  44. QMenu *myItemMenu;
  45. Mode myMode;
  46. bool leftButtonDown;
  47. QPointF startPoint;
  48.  
  49.  
  50. QFont myFont;
  51. DiagramTextItem *textItem;
  52. QColor myTextColor;
  53. QColor myItemColor;
  54. QColor myLineColor;
  55. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void DiagramScene::keyPressEvent(QKeyEvent *event)
  2. {
  3. if(event->key() == Qt::Key_Control)
  4. {
  5. std::cout << "Ctrl pressed" << endl;
  6. }
  7. }
To copy to clipboard, switch view to plain text mode 


Any hint on this?


Regards
Sajjad