31 from __future__
import division
33 from python_qt_binding.QtCore
import QPointF, QRectF, Qt
34 from python_qt_binding.QtGui
import QTransform
35 from python_qt_binding.QtWidgets
import QGraphicsView
41 super(InteractiveGraphicsView, self).
__init__(parent)
42 self.setObjectName(
'InteractiveGraphicsView')
50 self.setCursor(Qt.ClosedHandCursor)
53 self.setCursor(Qt.OpenHandCursor)
58 delta_scene = self.mapToScene(mouse_event.pos()) - self.mapToScene(self.
_last_pan_point)
59 if not delta_scene.isNull():
63 QGraphicsView.mouseMoveEvent(self, mouse_event)
66 if wheel_event.modifiers() == Qt.NoModifier:
68 delta = wheel_event.angleDelta().y()
69 except AttributeError:
70 delta = wheel_event.delta()
71 delta = max(min(delta, 480), -480)
72 mouse_before_scale_in_scene = self.mapToScene(wheel_event.pos())
74 scale_factor = 1 + (0.2 * (delta / 120.0))
75 scaling = QTransform(scale_factor, 0, 0, scale_factor, 0, 0)
76 self.setTransform(self.transform() * scaling)
78 mouse_after_scale_in_scene = self.mapToScene(wheel_event.pos())
79 center_in_scene = self.mapToScene(self.frameRect().center())
81 center_in_scene + mouse_before_scale_in_scene - mouse_after_scale_in_scene)
85 QGraphicsView.wheelEvent(self, wheel_event)
88 point = pointf.toPoint()
89 if pointf.x() == point.x()
and pointf.y() == point.y():
91 return self.mapToScene(point)
92 elif pointf.x() == point.x():
94 pointA = self.mapToScene((pointf + QPointF(0, -0.5)).toPoint())
95 pointB = self.mapToScene((pointf + QPointF(0, 0.5)).toPoint())
96 return (pointA + pointB) / 2.0
97 elif pointf.y() == point.y():
99 pointA = self.mapToScene((pointf + QPointF(-0.5, 0)).toPoint())
100 pointB = self.mapToScene((pointf + QPointF(0.5, 0)).toPoint())
101 return (pointA + pointB) / 2.0
104 pointA = self.mapToScene((pointf + QPointF(-0.5, -0.5)).toPoint())
105 pointB = self.mapToScene((pointf + QPointF(-0.5, 0.5)).toPoint())
106 pointC = self.mapToScene((pointf + QPointF(0.5, -0.5)).toPoint())
107 pointD = self.mapToScene((pointf + QPointF(0.5, 0.5)).toPoint())
108 return (pointA + pointB + pointC + pointD) / 4.0
def __init__(self, parent=None)
def _map_to_scene_f(self, pointf)
def mouseMoveEvent(self, mouse_event)
def mouseReleaseEvent(self, mouse_event)
def wheelEvent(self, wheel_event)
def mousePressEvent(self, mouse_event)