I got this piece of code :

Qt Code:
  1. void MainWindow::wheelEvent(QWheelEvent* event) {
  2.  
  3. //Get the position of the mouse before scaling, in scene coords
  4. QPointF pointBeforeScale(ui->graphWidget->mapToScene(event->pos()));
  5.  
  6. //Get the original screen centerpoint
  7. QPointF screenCenter = GetCenter(); //CurrentCenterPoint; //(visRect.center());
  8.  
  9. //Scale the view ie. do the zoom
  10. double scaleFactor = 1.15; //How fast we zoom
  11. if(event->delta() > 0) {
  12. //Zoom in
  13. ui->graphWidget->scale(scaleFactor, scaleFactor);
  14. } else {
  15. //Zooming out
  16. ui->graphWidget->scale(1.0 / scaleFactor, 1.0 / scaleFactor);
  17. }
  18.  
  19. //Get the position after scaling, in scene coords
  20. QPointF pointAfterScale(ui->graphWidget->mapToScene(event->pos()));
  21.  
  22. //Get the offset of how the screen moved
  23. QPointF offset = pointBeforeScale - pointAfterScale;
  24.  
  25. //Adjust to the new center for correct zooming
  26. QPointF newCenter = screenCenter + offset;
  27. SetCenter(newCenter);
  28. }
To copy to clipboard, switch view to plain text mode 

As you can see, the GraphicsView is ui->graphWidget . But it is a part of the mainwindow, and not built programattically. It is part of the ui form of the main window.