I have a QWidget with a QGraphicsView and a push button. The QGraphicsView has to take mouse press and release events to detect a swipe .At the same time push button should run a small function on clicked. I used an event filter in the QWidget to detect the mouse events.

Qt Code:
  1. bool Widget::eventFilter(QObject * obj, QEvent * event)
  2. {
  3.  
  4. // Capturing keyboard events for moving
  5. if( event->type() == QEvent::KeyPress )
  6. {
  7. //Do something
  8. }
  9.  
  10. //Capturing mouse events for swipe
  11. else if( event->type() == QEvent::MouseButtonPress)
  12. {
  13. QMouseEvent* mouseEvent = static_cast<QMouseEvent*> (event);
  14. swipe_startPoint = mouseEvent->pos();
  15. }
  16.  
  17. else if( event->type() == QEvent::MouseButtonRelease)
  18. {
  19. QMouseEvent* mouseEvent = static_cast<QMouseEvent*> (event);
  20. swipe_endPoint = mouseEvent->pos();
  21. swipeDirection();
  22. }
  23.  
  24. else
  25. {
  26. QWidget::eventFilter(obj,event);
  27. }
To copy to clipboard, switch view to plain text mode 

In the constructor of the Widget class i have the following
Qt Code:
  1. ui->graphicsView->installEventFilter(this);
To copy to clipboard, switch view to plain text mode 


The problem is that the button is getting clicked but the MouseButtonRelease event that sets the 'swipe_endPoint' value is not working.

When i set
Qt Code:
  1. ui->graphicsView->grabMouse();
To copy to clipboard, switch view to plain text mode 
the mouse pressed and released events are working perfectly but the button stops accepting the events.

Note : Using QT 5.6.0 in Ubuntu

Can you please help me overcome this problem.
Thanks in advance