Skip to content

Commit 5aefe93

Browse files
PR: Add option to disable zoom with Ctrl + mouse wheel (Preferences) (#24973)
Co-authored-by: Carlos Cordoba <[email protected]>
1 parent e7f37e8 commit 5aefe93

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

spyder/config/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
'show_dpi_message': True,
8787
'show_message_when_panes_are_empty': True,
8888
'max_recent_files': 20,
89+
'disable_zoom_mouse': False,
8990
}),
9091
('update_manager',
9192
{

spyder/plugins/application/confpage.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def setup_page(self):
7878
'check_stable_only',
7979
section='update_manager'
8080
)
81+
disable_zoom_mouse_cb = newcb(
82+
_("Disable zoom with mouse wheel"),
83+
'disable_zoom_mouse'
84+
)
8185

8286
# Decide if it's possible to activate or not single instance mode
8387
# ??? Should we allow multiple instances for macOS?
@@ -101,6 +105,7 @@ def setup_page(self):
101105
advanced_layout.addWidget(popup_console_box)
102106
advanced_layout.addWidget(check_update_cb)
103107
advanced_layout.addWidget(stable_only_cb)
108+
advanced_layout.addWidget(disable_zoom_mouse_cb)
104109

105110
advanced_widget = QWidget()
106111
advanced_widget.setLayout(advanced_layout)

spyder/plugins/editor/widgets/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,10 @@ def focusOutEvent(self, event):
11731173
def wheelEvent(self, event):
11741174
"""Reimplemented to emit zoom in/out signals when Ctrl is pressed"""
11751175
# This feature is disabled on MacOS, see spyder-ide/spyder#1510.
1176-
if sys.platform != 'darwin':
1176+
if (
1177+
sys.platform != 'darwin'
1178+
and not self.get_conf('disable_zoom_mouse', section='main')
1179+
):
11771180
if event.modifiers() & Qt.ControlModifier:
11781181
if hasattr(event, 'angleDelta'):
11791182
if event.angleDelta().y() < 0:

spyder/plugins/ipythonconsole/widgets/shell.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import typing
1919

2020
# Third party imports
21-
from qtpy.QtCore import Qt, Signal
21+
from qtpy.QtCore import Qt, Signal, QEvent
2222
from qtpy.QtGui import QClipboard, QTextCursor, QTextFormat
2323
from qtpy.QtWidgets import QApplication, QMessageBox
2424
from spyder_kernels.comms.frontendcomm import CommError
@@ -1556,6 +1556,16 @@ def focusOutEvent(self, event):
15561556
"""Reimplement Qt method to send focus change notification"""
15571557
self.sig_focus_changed.emit()
15581558
return super().focusOutEvent(event)
1559+
1560+
def eventFilter(self, obj, event):
1561+
etype = event.type()
1562+
if (
1563+
etype == QEvent.Wheel
1564+
and self._control_key_down(event.modifiers())
1565+
and self.get_conf('disable_zoom_mouse', section='main')
1566+
):
1567+
return False
1568+
return super().eventFilter(obj, event)
15591569

15601570
# ---- Python methods
15611571
def __repr__(self):

spyder/plugins/plots/widgets/figurebrowser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,10 @@ def eventFilter(self, widget, event):
499499
# ---- Zooming
500500
if event.type() == QEvent.Wheel and not self.auto_fit_plotting:
501501
modifiers = QApplication.keyboardModifiers()
502-
if modifiers == Qt.ControlModifier:
502+
if (
503+
modifiers == Qt.ControlModifier
504+
and not self.get_conf('disable_zoom_mouse', section='main')
505+
):
503506
if event.angleDelta().y() > 0:
504507
self.zoom_in()
505508
else:

spyder/widgets/browser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ def eventFilter(self, widget, event):
414414
self.sig_focus_in_event.emit()
415415
elif event.type() == QEvent.FocusOut:
416416
self.sig_focus_out_event.emit()
417+
418+
if (
419+
event.type() == QEvent.Wheel
420+
and event.modifiers() & Qt.ControlModifier
421+
and self.get_conf("disable_zoom_mouse", section="main")
422+
):
423+
return True
424+
417425
return super().eventFilter(widget, event)
418426

419427

0 commit comments

Comments
 (0)