title: Zoom to mouse position - pyside6
body: <p>Hello I am tring to implement simple image widget with zoom to mouse position. I combined the example at <a href="https://stackoverflow.com/questions/3725342/zooming-in-out-on-a-mouser-point">Zooming in/out on a mouser point ?</a> and <a href="https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html" rel="nofollow noreferrer">https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html</a>. However the image do not scale as expected and the scale bars do not update appropriately either. Here is my code:</p>
  <pre><code>import sys
  from PySide6 import QtWidgets
  from PySide6.QtCore import Qt
  from PIL.ImageQt import ImageQt
  from PySide6.QtGui import QPixmap
  from PySide6.QtWidgets import QDialog, QVBoxLayout, QLabel, QScrollArea
  
  
  class MyScrollArea(QScrollArea):
      def __init__(self, imageWidget):
          # initialize widget
          super().__init__()
          self.setWidget(imageWidget)
          self.myImageWidget = imageWidget
          self.oldScale = 1
          self.newScale = 1
  
      def wheelEvent(self, event) -&gt; None:
          if event.angleDelta().y() &lt; 0:
              # zoom out
              self.newScale = 0.8
          else:
              # zoom in
              self.newScale = 1.25
  
          # compute scrollbar positions
          scrollBarPosHorizontal = self.horizontalScrollBar().value()
          scrollBarPosVertical = self.verticalScrollBar().value()
          deltaToPos = (event.position() / self.oldScale) - (self.myImageWidget.pos() / self.oldScale)
          delta = deltaToPos * self.newScale - deltaToPos * self.oldScale
  
          # resize image
          self.myImageWidget.resize(self.myImageWidget.size() * self.newScale)
  
          # set scrollbars
          self.horizontalScrollBar().setValue(scrollBarPosHorizontal+delta.x())
          self.verticalScrollBar().setValue(scrollBarPosVertical+delta.y())
  
          # save old scale
          self.oldScale = self.newScale
  
  class ImageViewer(QDialog):
      def __init__(self, img):
          # initialize widget
          super().__init__()
          self.setWindowTitle('Zoom example')
          self.imageWidget = QLabel()
          self.imageWidget.installEventFilter(self)
          self.imageWidget.setAlignment(Qt.AlignCenter)
          self.pixmap = QPixmap.fromImage(img)
          self.imageWidget.setPixmap(self.pixmap)
  
          # create scroll area
          self.scrollArea = MyScrollArea(self.imageWidget)
  
          # insert to layout
          self.layout = QVBoxLayout()
          self.layout.addWidget(self.scrollArea)
          self.setLayout(self.layout)
  
  
  if __name__ == '__main__':
      # prepare app
      app = QtWidgets.QApplication(sys.argv)
  
      # prepare image
      image = ImageQt(&quot;test.png&quot;)
  
      # create viewer widget
      MyWidget = ImageViewer(image)
      MyWidget.show()
  
      # close app
      sys.exit(app.exec())
  </code></pre>
  <p>The image do not scale to mouse point at all. What am I doing wrong?</p>