[detection view] improving zooming under mac
This commit is contained in:
parent
1e86a74549
commit
6244f7fdbe
@ -92,6 +92,7 @@ class DetectionView(QWidget):
|
||||
self._view = QGraphicsView()
|
||||
self._view.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
self._view.setMouseTracking(True)
|
||||
self._mouseEnabled = True
|
||||
self._zoomFactor = 1.15
|
||||
self._minZoom = 0.1
|
||||
self._maxZoom = 10
|
||||
@ -102,16 +103,23 @@ class DetectionView(QWidget):
|
||||
self.setLayout(lyt)
|
||||
|
||||
def wheelEvent(self, event):
|
||||
if event.angleDelta().y() > 0: # Zoom in
|
||||
factor = self._zoomFactor
|
||||
else: # Zoom out
|
||||
factor = 1 / self._zoomFactor
|
||||
|
||||
newZoom = self._currentZoom * factor
|
||||
if not self._mouseEnabled:
|
||||
super().wheelEvent(event)
|
||||
return
|
||||
modifiers = event.modifiers()
|
||||
if modifiers == Qt.ControlModifier:
|
||||
delta = event.angleDelta().x()
|
||||
if delta == 0:
|
||||
delta = event.angleDelta().y()
|
||||
sc = 1.001 ** delta
|
||||
self._view.scale(sc, sc)
|
||||
else:
|
||||
super().wheelEvent(event)
|
||||
|
||||
if self._minZoom < newZoom < self._maxZoom:
|
||||
self._view.scale(factor, factor)
|
||||
self._currentZoom = newZoom
|
||||
# elif modifiers == Qt.ShiftModifier:
|
||||
# print("Shift key pressed")
|
||||
# elif modifiers == Qt.AltModifier:
|
||||
# print("Alt key pressed")
|
||||
|
||||
def setImage(self, image: QImage):
|
||||
self._img = image
|
||||
|
Loading…
Reference in New Issue
Block a user