title: Resizing QPixmap while maintaining aspect ratio
body: <p>To keep the aspect ratio of an image fixed while resizing the <code>QDialog</code> I've tried the following: </p>
  
  <pre><code>import os, sys
  from PyQt5.QtWidgets import QApplication, QDialog, QGridLayout, QLabel
  from PyQt5.QtGui import QPixmap
  from PyQt5.QtCore import Qt
  
  class Dialog(QDialog):
      def __init__(self, parent=None):
          super(Dialog, self).__init__(parent)
          self.pic = QLabel()
          self.pic.resizeEvent = onResize 
          self.pic.setPixmap(QPixmap(os.getcwd() + "/images/1.jpg").scaled(300, 200, Qt.KeepAspectRatio,Qt.SmoothTransformation))
          layout = QGridLayout()
          layout.addWidget(self.pic, 1, 0)
          self.setLayout(layout)
  
  def onResize(event):
      size = dialog.pic.size()
      dialog.pic.setPixmap(QPixmap(os.getcwd() + "/images/1.jpg").scaled(size, Qt.KeepAspectRatio, Qt.SmoothTransformation))    
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      dialog = Dialog()
      dialog.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>As espected the Image starts with 300x200. It can be enlarged as wished but the size can't be reduced at all (down to 300x200 after enlargement). <code>onResize</code> seems to lack something.</p>