Here is a simple re-implementation of mouse events for a QGraphicsView:

Qt Code:
  1. void kadeView::mousePressEvent (QMouseEvent * event )
  2. {
  3. if (event->button() == Qt::MidButton) //pan
  4. {
  5. isPanning=1;
  6. saved_cursor=viewport()->cursor();
  7. setCursor(Qt::ClosedHandCursor);
  8. mouse_pos=mapToScene(event->pos());
  9. event->accept();
  10. return;
  11. };
  12. QGraphicsView::mousePressEvent(event);
  13. };
  14.  
  15. void kadeView::mouseMoveEvent ( QMouseEvent * event )
  16. {
  17. if(isPanning==1)
  18. {
  19. QPointF delta(mouse_pos-mapToScene(event->pos()));
  20. QRectF r1(sceneRect());
  21. r1.translate(delta.x(),delta.y());
  22. setSceneRect(r1);
  23. //translate(delta.x(),delta.y());
  24. //ensureVisible(pan_rect.x()-line.dx(),pan_rect.y()-line.dy(),pan_rect.width(),pan_rect.height());
  25. //centerOn(pan_rect.center().x()-line.dx(),pan_rect.center().y()-line.dy());
  26. event->accept();
  27. return;
  28. };
  29. QGraphicsView::mouseMoveEvent(event);
  30. };
  31.  
  32. void kadeView::mouseReleaseEvent ( QMouseEvent * event )
  33. {
  34. if(isPanning==1)
  35. {
  36. isPanning=0;
  37. setCursor(saved_cursor);
  38. event->accept();
  39. return;
  40. };
  41. QGraphicsView::mouseReleaseEvent(event);
  42. };
To copy to clipboard, switch view to plain text mode 

It pans the view on middle mouse click and drag.
Can someone explain me why the only command that works is the setSceneRect() in mouseMoveEvent, and not the commented ones?
If I uncomment and replace setSceneRect with any of the translate(), centerOn(), ensureVisible() nothing is happening in the view...

Thank you in advance