Replace

Qt Code:
  1. graphicsView.show();
  2.  
  3. MainWindow w;
To copy to clipboard, switch view to plain text mode 

with

Qt Code:
  1. MainWindow w;
  2.  
  3. w.setCentralWidget(&graphicsView);
To copy to clipboard, switch view to plain text mode 

You created two distinct widgets and showed them.
You need to add the graphics view to the main window.