title: How to scale images in QGraphicsScene? (Qt 5.11)
body: <p>I am having some trouble getting the image in an image previewer correctly scale to the window size.  I have a <code>ImgViewer</code> window for previewing images, and want to update the displayed image whenever a new file is chosen by the main window. The images are being updated correctly as new ones are clicked in the main window, but the scaling is not applying.  The images always show up way too large for the <code>ImgViewer</code> window.</p>
  
  <p>Here is the code I wrote for the image update function:</p>
  
  <pre><code>void ImgViewer::update_img(QString img_path){
      img_object = new QImage();
      img_object-&gt;load(img_path);
      image = QPixmap::fromImage(*img_object);
      QPixmap scaled_img = image.scaled(img_object-&gt;size(), Qt::KeepAspectRatio);
  
      scene = new QGraphicsScene(this);
      scene-&gt;addPixmap(scaled_img);
      scene-&gt;setSceneRect(scaled_img.rect());
  
      ui-&gt;graphicsView-&gt;setScene(scene);
  }
  </code></pre>
  
  <p>Do I need to reset the scene every time the window is resized?</p>