我正在开发一个简单的电路模拟器,我在鼠标滚轮上添加了一个缩放选项,因为它可能对大型项目有用:
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
我目前有以下resetZoom方法,但我觉得它很粗糙,不太优雅:
def resetZoom(self):
self.scale(1/self.zoomLevel, 1/self.zoomLevel)
self.zoomLevel = 1
有没有办法将视口重置为其真实的初始大小?由于某种原因,我在任何地方都找不到这些信息。
看起来resetTransform应该做你想做的事情。