def wheelEvent(self, event: QWheelEvent): if event.modifiers() & Qt.ControlModifier \ and event.buttons() == Qt.NoButton: # Zoom delta = event.angleDelta().y() # use mouse position as anchor while zooming anchor = self.transformationAnchor() self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.__setZoomLevel(self.__zoomLevel + 10 * delta / 120) self.setTransformationAnchor(anchor) event.accept() elif event.source() == Qt.MouseEventNotSynthesized \ and (event.angleDelta().x() == 0 \ and not self.verticalScrollBar().isVisible()) \ or (sys.platform == 'darwin' and event.modifiers() & Qt.ShiftModifier or sys.platform != 'darwin' and event.modifiers() & Qt.AltModifier): # Scroll horizontally x, y = event.angleDelta().x(), event.angleDelta().y() sign_value = x if x != 0 else y sign = 1 if sign_value >= 0 else -1 new_angle_delta = QPoint(sign * max(abs(x), abs(y), sign_value), 0) new_pixel_delta = QPoint(0, 0) new_modifiers = event.modifiers() & ~(Qt.ShiftModifier | Qt.AltModifier) new_event = QWheelEvent(event.pos(), event.globalPos(), new_pixel_delta, new_angle_delta, event.buttons(), new_modifiers, event.phase(), event.inverted(), event.source()) event.accept() super().wheelEvent(new_event) else: super().wheelEvent(event)
def wheelEvent(self, event: QWheelEvent): # Zoom if event.modifiers() & Qt.ControlModifier \ and event.buttons() == Qt.NoButton: delta = event.angleDelta().y() # use mouse position as anchor while zooming anchor = self.transformationAnchor() self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.__setZoomLevel(self.__zoomLevel + 10 * delta / 120) self.setTransformationAnchor(anchor) event.accept() # Scroll horizontally elif self.__should_scroll_horizontally(event): x, y = event.angleDelta().x(), event.angleDelta().y() sign_value = x if x != 0 else y sign = 1 if sign_value >= 0 else -1 new_angle_delta = QPoint(sign * max(abs(x), abs(y), sign_value), 0) new_pixel_delta = QPoint(0, 0) new_modifiers = event.modifiers() & ~(Qt.ShiftModifier | Qt.AltModifier) new_event = QWheelEvent(event.pos(), event.globalPos(), new_pixel_delta, new_angle_delta, event.buttons(), new_modifiers, event.phase(), event.inverted(), event.source()) event.accept() super().wheelEvent(new_event) else: super().wheelEvent(event)
def wheelEvent(self, event: QWheelEvent): if event.source() == Qt.MouseEventNotSynthesized and \ (event.modifiers() & Qt.ShiftModifier and sys.platform == 'darwin' or event.modifiers() & Qt.AltModifier and sys.platform != 'darwin'): new_event = QWheelEvent(event.pos(), event.globalPos(), event.pixelDelta(), event.angleDelta(), event.buttons(), Qt.NoModifier, event.phase(), event.inverted(), Qt.MouseEventSynthesizedByApplication) event.accept() super().wheelEvent(new_event) else: super().wheelEvent(event)
def wheelEvent(self, event: QWheelEvent): # use mouse position as anchor while zooming self.setTransformationAnchor(2) if event.modifiers() & Qt.ControlModifier and event.buttons( ) == Qt.NoButton: delta = event.angleDelta().y() if (QT_VERSION >= 0x050500 and event.source() != Qt.MouseEventNotSynthesized and abs(delta) < 50): self.change_zoom(delta / 10) else: self.change_zoom(copysign(1, delta)) else: super().wheelEvent(event)
def __should_scroll_horizontally(self, event: QWheelEvent): if event.source() != Qt.MouseEventNotSynthesized: return False if (event.modifiers() & Qt.ShiftModifier and sys.platform == 'darwin' or event.modifiers() & Qt.AltModifier and sys.platform != 'darwin'): return True if event.angleDelta().x() == 0: vBar = self.verticalScrollBar() yDelta = event.angleDelta().y() direction = yDelta >= 0 edgeVBarValue = vBar.minimum() if direction else vBar.maximum() return vBar.value() == edgeVBarValue return False
def wheelEvent(self, event: QWheelEvent): # use mouse position as anchor while zooming self.setTransformationAnchor(2) if event.modifiers() & Qt.ControlModifier \ and event.buttons() == Qt.NoButton: delta = event.angleDelta().y() if QT_VERSION >= 0x050500 \ and event.source() != Qt.MouseEventNotSynthesized \ and abs(delta) < 50: self.change_zoom(delta / 10) else: self.change_zoom(copysign(1, delta)) else: super().wheelEvent(event)