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