예제 #1
0
 def wheelEvent(self, event: QWheelEvent) -> None:  # pylint: disable=invalid-name
     """With Ctrl depressed, zoom the current image, otherwise fire the
     next/previous functions."""
     modifiers = QApplication.keyboardModifiers()
     if event.angleDelta().y() == 120 and modifiers == Qt.ControlModifier:
         self.view.scale(0.75, 0.75)
     elif event.angleDelta().y() == 120:
         self.previous()
     elif event.angleDelta().y(
     ) == -120 and modifiers == Qt.ControlModifier:
         self.view.scale(1.25, 1.25)
     elif event.angleDelta().y() == -120:
         self.next()
예제 #2
0
파일: glwidget.py 프로젝트: xmarduel/pycut
    def wheelEvent(self, we: QtGui.QWheelEvent):
        if self.m_zoom > 0.1 and we.angleDelta().y() < 0:
            self.m_xPan -= ((float)(we.position().x() / self.width() - 0.5 + self.m_xPan)) * (1 - 1 / ZOOMSTEP)
            self.m_yPan += ((float)(we.position().y() / self.height() - 0.5 - self.m_yPan)) * (1 - 1 / ZOOMSTEP)

            self.m_zoom /= ZOOMSTEP
        elif self.m_zoom < 10 and we.angleDelta().y() > 0:
            self.m_xPan -= ((float)(we.position().x() / self.width() - 0.5 + self.m_xPan)) * (1 - ZOOMSTEP)
            self.m_yPan += ((float)(we.position().y() / self.height() - 0.5 - self.m_yPan)) * (1 - ZOOMSTEP)

            self.m_zoom *= ZOOMSTEP

        self.updateProjection()
        self.updateView()
예제 #3
0
 def zoom(view: QGraphicsView, e: QWheelEvent, mode: str):
     zoom_in_factor = 1.25
     zoom_out_factor = 1 / zoom_in_factor
     view.setTransformationAnchor(QGraphicsView.NoAnchor)
     view.setResizeAnchor(QGraphicsView.NoAnchor)
     old_pos = view.mapToScene(int(e.position().x()), int(e.position().y()))
     if mode == "zoom-in":
         zoom_factor = zoom_in_factor
     else:
         zoom_factor = zoom_out_factor
     view.scale(zoom_factor, zoom_factor)
     new_pos = view.mapToScene(int(e.position().x()), int(e.position().y()))
     delta = new_pos - old_pos
     view.translate(delta.x(), delta.y())
예제 #4
0
    def wheelEvent(self, event: QWheelEvent) -> NoReturn:
        mouse_pos = event.position()
        scene_pos = self.mapToScene(mouse_pos.toPoint())
        view_w = self.viewport().width()
        view_h = self.viewport().height()
        h_scale = mouse_pos.x() / view_w
        v_scale = mouse_pos.y() / view_h

        wheel_delta = event.angleDelta().y()
        if wheel_delta > 0:
            self.scale(1.2, 1.2)
        else:
            self.scale(1 / 1.2, 1 / 1.2)
        view_point = self.transform().map(scene_pos)
        self.horizontalScrollBar().setValue(view_point.x() - view_w * h_scale)
        self.verticalScrollBar().setValue(view_point.y() - view_h * v_scale)
        self._update_fixed_widgets()
예제 #5
0
 def wheelEvent(self, event: QWheelEvent) -> None:
     result = super().wheelEvent(event)
     # repaint previously hovered row on scroll avoid repaint artifacts
     index = self.model().index(self.hoverIndexRow, 0)
     self.hoverIndexRow = self.indexAt(event.position().toPoint()).row()
     rect = self.visualRect(index)
     rect.setLeft(0)
     rect.setRight(self.viewport().width())
     self.viewport().repaint(rect)
     return result
예제 #6
0
    def wheelEvent(self, event: QWheelEvent):
        numSteps = float(event.angleDelta().y()) / 1000

        oldWorldPos = self.mapToScene(self._currentCursorPosition.toPoint())
        self._zoom = min(self._zoom + numSteps, 0)
        self.UpdateView()
        newWorldPos = self.mapToScene(self._currentCursorPosition.toPoint())

        delta = newWorldPos - oldWorldPos
        self._offset -= delta

        self.UpdateView()
예제 #7
0
 def change_view_zoom(view: QGraphicsView, e: QWheelEvent):
     if e.angleDelta().y() > 0 and view.transform().m11() < 1000.0:
         ViewTools.zoom(view, e, "zoom-in")
     elif e.angleDelta().y() < 0 and view.transform().m11() > 0.01:
         ViewTools.zoom(view, e, "zoom-out")