title: Zoom in and out in widget
body: <p>How can I make a zoom effect with key input on a widget? The widget is inside a scroll area and there are some drawings made with QPainter who change with user input. The zoom would affect the length of the scrolling bar, the closer you are, the smaller the bar becomes. The zoom at minimum level should make the scroll bar as big as the widget area, so all the content in the widget could be visualized.</p>
  
  <p>MRE:</p>
  
  <pre class="lang-py prettyprint-override"><code>from PyQt5 import QtCore, QtWidgets
  from PyQt5.QtWidgets import QWidget
  from PyQt5.QtCore import Qt
  from PyQt5.QtGui import QPainter, QPen, QColor
  import sys
  
  
  class Diedrico(QWidget):
      def __init__(self, parent):
          super().__init__(parent)
  
      def paintEvent(self, event):
          qp = QPainter(self)
          qp.setPen(QPen(QColor(Qt.black), 5))
          qp.drawRect(500, 500, 1000, 1000)
  
  
  class UiVentana(QtWidgets.QMainWindow):
      def __init__(self, parent=None):
          super(UiVentana, self).__init__(parent)
          self.resize(520, 520)
          self.widget_central = QtWidgets.QWidget(self)
          scrol = QtWidgets.QScrollArea(self.widget_central)
          scrol.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
          scrol.setGeometry(QtCore.QRect(10, 10, 500, 500))
          scrol.setWidgetResizable(False)
  
          contenido = QtWidgets.QWidget()
          contenido.setGeometry(QtCore.QRect(0, 0, 2000, 2000))
          scrol.setWidget(contenido)
  
          self.Diedrico = Diedrico(contenido)
          self.Diedrico.setGeometry(QtCore.QRect(0, 0, 2000, 2000))
          self.setCentralWidget(self.widget_central)
  
  
  if __name__ == "__main__":
      app = QtWidgets.QApplication(sys.argv)
      ui = UiVentana()
      ui.show()
      sys.exit(app.exec_())
  </code></pre>