It looks like resetTransform should do what you want.
Most efficient way to reset scaling factor of a QViewPort in PyQt4
-
06-07-2023 - |
Pergunta
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.
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow