Skip to content

Commit e933054

Browse files
committed
Make + and - zoom in and out, respectively
And do it under the cursor, for greater control.
1 parent 10abe13 commit e933054

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/ndv/viewer/_viewer.py

+9
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ def __init__(
153153
# ROI
154154
self._roi: PRoiHandle | None = None
155155

156+
# closest data point under the mouse
157+
self._data_coords: tuple[int, int] = (0, 0)
158+
156159
# WIDGETS ----------------------------------------------------
157160

158161
# the button that controls the display mode of the channels
@@ -731,6 +734,7 @@ def _update_hover_info(self, event: QMouseEvent) -> bool:
731734

732735
x = int(x)
733736
y = int(y)
737+
self._data_coords = (x, y)
734738
text = f"[{y}, {x}]"
735739
# TODO: Can we use self._canvas.elements_at?
736740
for n, handles in enumerate(self._img_handles.values()):
@@ -765,6 +769,11 @@ def keyPressEvent(self, a0: QKeyEvent | None) -> None:
765769
if a0.key() == Qt.Key.Key_Delete and self._selection is not None:
766770
self._selection.remove()
767771
self._selection = None
772+
elif a0.key() in [Qt.Key.Key_Plus, Qt.Key.Key_Equal]:
773+
self._canvas._camera.zoom(factor=0.667, center=self._data_coords)
774+
elif a0.key() in [Qt.Key.Key_Minus, Qt.Key.Key_Underscore]:
775+
self._canvas._camera.zoom(factor=1.5, center=self._data_coords)
776+
768777

769778
def _update_roi_button(self, event: QMouseEvent) -> bool:
770779
if self._add_roi_btn.isChecked():

0 commit comments

Comments
 (0)