I have a QGraphicsView where I'm allowing the user to change the zoom using CTRL-MouseWheel. The way QGraphicsView::scale(float, float) is setup it requires you to store the previous scale.

Ex:
Qt Code:
  1. def wheelEvent(self, evt):
  2. mods = evt.modifiers()
  3. if mods == Qt.ControlModifier and evt.orientation() == Qt.Vertical:
  4. # Most mouse types work in steps of 15 degrees
  5. # in which case the delta value is a multiple of 120;
  6. # i.e., 120 units * 1/8 = 15 degrees
  7. numDegrees = evt.delta() / 8
  8. numSteps = numDegrees / 15
  9.  
  10. newScale = self._scale + ((5*numSteps)/100.0)
  11. if newScale > 0.0 and newScale < 5.0:
  12. self.resetMatrix()
  13. self.scale(newScale, newScale)
  14. self._scale = newScale
  15. return
  16. QtGui.QGraphicsView.wheelEvent(self, evt)
To copy to clipboard, switch view to plain text mode 

First off... is there a better way of doing this?

This all falls apart because it relies on the fact that "self._scale" represents the current scale factor applied to the matrix. As well as a myriad of other issues that are caused by calling resetMatrix().

So I was wondering if there is a way to derive the current scale factor. I assumed there isn't since its not part of the public API... so I'm hoping someone has come up with a smarter way to zoom in/out.

By the way this works fine if I just want to zoom in/out but I'm also doing a fitToSelection() call which messes up everything.

Full code is available here in case anyone is interested:
http://www.qtcentre.org/forum/f-qt-p...iew-15739.html