title: How can I modify my Qt PaintEvent code to scale a displayed Pixmap relative to the mouse pointer
body: <p>I have a (so far) fairly simple QWidget (size of say 300 * 300) that I am using to display a large QPixmap (e.g 5184 * 3456).   The key parts of the code read as follows:</p>
  <pre><code>void DSSImageWidget::resizeEvent(QResizeEvent* e)
  {
      QSize sz = e-&gt;size();
      qreal hScale = (qreal)sz.width() / (m_pixmap.width() + 4);
      qreal vScale = (qreal)sz.height() / (m_pixmap.height() + 4);
      m_scale = std::min(hScale, vScale);
  
      update();
      Inherited::resizeEvent(e);
  }
  
  void DSSImageWidget::paintEvent(QPaintEvent* event)
  {
      QPainter painter;
      painter.begin(this);
      painter.setRenderHint(QPainter::Antialiasing);
      painter.setRenderHint(QPainter::SmoothPixmapTransform);
      
      //QPointF whereScaled = m_where / (m_zoom * m_scale);
      //qDebug() &lt;&lt; &quot;m_where:&quot; &lt;&lt; m_where.x() &lt;&lt; m_where.y();
      //qDebug() &lt;&lt; whereScaled.x() &lt;&lt; &quot; &quot; &lt;&lt; whereScaled.y();
  
      //painter.translate(-m_where);
      painter.scale(m_zoom*m_scale, m_zoom*m_scale);
      //painter.translate(m_where);
  
      painter.drawPixmap(QPointF(0.0, 0.0), m_pixmap);
  
      painter.setPen(QPen(QColor(255, 0, 0, alpha), 0.25, Qt::SolidLine, Qt::FlatCap, Qt::BevelJoin));
      painter.setBrush(Qt::NoBrush);
      painter.drawRect(QRectF(0, 0, m_pixmap.width(), m_pixmap.height()).adjusted(-2, -2, 2, 2));
      painter.end();
  }
  
  void DSSImageWidget::wheelEvent(QWheelEvent* e)
  {
      qreal degrees = -e-&gt;angleDelta().y() / 8.0;
      //
      // If zooming in and zoom factor is currently 1.0
      // then remember mouse location
      //
      if ((degrees &gt; 0) &amp;&amp; (m_zoom == 1.0))
      {
          m_where = e-&gt;position();
      }
      qreal steps = degrees / 60.0;
      qreal factor = m_zoom * std::pow(1.125, steps);
      
      m_zoom = std::clamp(factor, 1.0, 5.0);
      update();
      Inherited::wheelEvent(e);
  }
  </code></pre>
  <p>This scales the pixmap about the window origin which is a good start, but it's not what I want.  I want it to scale the pixmap so that the part of the image under the mouse pointer remains where it is and the image expands around that point.</p>
  <p>I've played all sorts of tunes with the painter.translate() calls and the location I use to actually draw the pixmap, but I've so far failed with flying colours :).</p>
  <p>Please could someone who knows how this stuff actually works put me out of my misery and tell me how I achieve my objective here?</p>
  <p>Thank you</p>