title: Preserve aspect ratio during minimize/maximize when displaying image?
body: <p>I'm trying to implement a scalable image widget with qt creator that will preserve the aspect ratio of the image. All the examples or posts I've found suggest extending QLabel and reimplementing resizeEvent. This is what I've done and it almost works, but for a few problems.</p>
  <ol>
  <li><p>When the main window first opens the images grow slightly and expand the size of the main window (this is not too big a problem).</p>
  </li>
  <li><p>When I maximize the window all the images scale up, but when I unmaximize the window the images fail to scale back down.</p>
  </li>
  </ol>
  <p>I have tried changing the resizeEvents of both the QLabel subclass (called ClickableImage) and the parent widget that holds the layout containing the ClickableImage. Here is some of the relevant code.</p>
  <pre><code>void ClickableImage::resizeEvent(QResizeEvent *e)
  {
      qDebug() &lt;&lt; &quot;Resizing : &quot; &lt;&lt; ticker;
      ticker++;
  
      int w = e-&gt;size().width();
      int h = e-&gt;size().height();
  
      qDebug() &lt;&lt; &quot;W : &quot; &lt;&lt; w;
      qDebug() &lt;&lt; &quot;H : &quot; &lt;&lt; h;
  
      image = QPixmap(fname);
      image = image.scaled(w-7, h-7, Qt::KeepAspectRatio);
      setPixmap(image);
  }
  </code></pre>
  <p>Also, I've read the following sources,</p>
  <p><a href="https://stackoverflow.com/questions/8211982/qt-resizing-a-qlabel-containing-a-qpixmap-while-keeping-its-aspect-ratio">Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio</a></p>
  <p><a href="https://docs.huihoo.com/qt/4.2/desktop-screenshot.html" rel="nofollow noreferrer">https://docs.huihoo.com/qt/4.2/desktop-screenshot.html</a></p>
  <p>Thanks.</p>