[PyQt] How to tell when QGraphicsView's transformation matrix has been changed?

TP wingusr at gmail.com
Mon Oct 11 13:18:25 BST 2010


I am trying to implement an image processing application that will
have multiple image viewers created with a subclass of QGraphicsView.
I need to be able to optionally keep all the image viewers in sync
with respect to zoom and position as the user clicks on the
scrollbars, uses the scroll wheel to zoom, uses menus to fit the view
to the window, etc.

Looking at C:\Qt\4.6.1\src\gui\graphicsview\qgraphicsview.cpp it seems
like I should be able to do the following:

  class ImageViewerView(QtGui.QGraphicsView):
      def __init__(self, scene=None, parent=None):
          if scene:
              super(ImageViewerView, self).__init__(scene, parent)
          else:
              super(ImageViewerView, self).__init__(parent)

      def setTransform(self, QTransform, combine=False):
          super(ImageViewerView, self).setTransform(QTransform, combine)
          print("transform = %s, %s" % (QTransform, combine))

to keep track of view changes since things like fitInView() calls
scale() which in turns calls setTransform().

However, when I run my test application I never seem to see any calls
to setTransform()?

So... how does one determine when a QGraphicsView's transform has been
changed? I didn't see any applicable built-in signals, so I figured
I'd just emit my own, but now I can't quite see where to do that.

Or maybe there's an entirely different way to track changes to a QGraphicsView?


More information about the PyQt mailing list