سؤال

I'm working on a simple electrical circuit simulator and I added a zoom option on the mousewheel since it could be useful for big projects:

def wheelEvent(self, event):
    self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)

    zoomInFactor = 1.15
    zoomOutFactor = 1 / 1.15

    if event.delta() > 0 and self.zoomLevel < 3:
        self.scale(zoomInFactor, zoomInFactor)
        self.zoomLevel = self.zoomLevel*zoomInFactor

    elif event.delta() < 0 and self.zoomLevel > 1/3.0:
        self.scale(zoomOutFactor, zoomOutFactor)
        self.zoomLevel = self.zoomLevel*zoomOutFactor

I currently have the following resetZoom method, but I feel like it's hacky and not very elegant:

def resetZoom(self):
    self.scale(1/self.zoomLevel, 1/self.zoomLevel)
    self.zoomLevel = 1

Is there a way to reset the viewport to its true initial size? For some reason I could not find this information anywhere.

هل كانت مفيدة؟

المحلول

It looks like resetTransform should do what you want.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top