Quote Originally Posted by Lykurg View Post
Install the filter on the scene or view, not on the item.
Qt Code:
  1. this->installEventFilter(this);
  2. //...
  3. return QGraphicsView::eventFilter(ob, e);
To copy to clipboard, switch view to plain text mode 
of course i try that one too ....

my full code
Qt Code:
  1. RecRepView::RecRepView(QWidget *parent)
  2. : QGraphicsView(parent)
  3. {
  4. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  5. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  6. setFrameShape(QFrame::NoFrame);
  7. setCacheMode(CacheBackground);
  8. setViewportUpdateMode(FullViewportUpdate);
  9. setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
  10. setStyleSheet("background:#00002E");
  11. QRectF bounds(0, -20, 700, 500);
  12. scene = new QGraphicsScene(bounds, this);
  13. setScene(scene);
  14. this->installEventFilter(this);
  15. signalMapper = new QSignalMapper();
  16. int i =0;
  17. mapValue[i] = STARTVALUE;
  18. button1 = new GraphButton(QRectF(0,0, 150, 40), 1);
  19. button1->setFlag(QGraphicsItem::ItemIsSelectable);
  20. button1->setPos(475, 330);
  21. scene->addItem(button1);
  22. connect(button1, SIGNAL(activated()), signalMapper, SLOT(map()));
  23. signalMapper->setMapping(button1,mapValue[i]);
  24. i++;
  25.  
  26.  
  27. mapValue[i] = STOPVALUE;
  28. button2 = new GraphButton(QRectF(0,0, 150, 40), 2);
  29. button2->setFlag(QGraphicsItem::ItemIsSelectable);
  30. button2->setPos(475, 400);
  31. scene->addItem(button2);
  32. connect(button2, SIGNAL(activated()), signalMapper, SLOT(map()));
  33. signalMapper->setMapping(button2,mapValue[i]);
  34.  
  35. logout = new BackItem(QRectF(0, 0, 70, 65));
  36. logout->setPos(20, 405);
  37. logout->setFlag(QGraphicsItem::ItemIsSelectable);
  38. // log connect(logout, SIGNAL(closeSignal()), qApp, SLOT(quit()));
  39. scene->addItem(logout);
  40.  
  41. connect(signalMapper, SIGNAL(mapped(int )), this, SIGNAL(activated(int)));
  42.  
  43. connect(this, SIGNAL(activated(int )), this, SLOT(recRepSlot(int )));
  44.  
  45. }
  46.  
  47. void RecRepView ::resizeEvent(QResizeEvent *event)
  48. {
  49. QGraphicsView::resizeEvent(event);
  50. fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
  51. }
  52.  
  53. void RecRepView::drawBackground(QPainter *painter, const QRectF &rect)
  54. {
  55. Q_UNUSED(rect);
  56.  
  57. QRectF rects(450,310, 200, 160);
  58. QPen pen(QColor(211, 210, 212), 0.5);
  59. painter->setBrush(QColor(128, 128, 128));
  60. painter->setPen(pen);
  61. painter->drawRect(rects);
  62.  
  63. }bool RecRepView:: eventFilter(QObject *ob, QEvent *e)
  64. {
  65. if(ob == logout && e->type() == QEvent::KeyPress) {
  66. const QKeyEvent *ke = static_cast<QKeyEvent *>(e);
  67. if(ke->key()==Qt::Key_F1){
  68. printf("is it coming inside ..\n");
  69.  
  70. }
  71. return true;
  72. }
  73. return QWidget::eventFilter(ob, e);
  74. }
  75. void RecRepView::recRepSlot(int value)
  76. {
  77. printf("the value coming inside :%d \n", value);
  78.  
  79. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. GraphButton::GraphButton(const QRectF &rect, int itemNo)
  2. {
  3. }
  4.  
  5. void GraphButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
  6. {
  7. if(event->button() != Qt::LeftButton)
  8. {
  9. QGraphicsRectItem::mousePressEvent(event);
  10. return;
  11. }
  12. emit activated();
  13. }
To copy to clipboard, switch view to plain text mode 

please help ....