Skip to content

Commit 92c4212

Browse files
[Bug]: qtagg reports wrong button when Option is released before the mouse button
Fixes matplotlib#31899
1 parent a47ac21 commit 92c4212

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎lib/matplotlib/backends/backend_qt.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def __init__(self, figure=None):
239239
self._is_drawing = False
240240
self._draw_rect_callback = lambda painter: None
241241
self._in_resize_event = False
242+
self._pressed_buttons = {}
242243

243244
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_OpaquePaintEvent)
244245
self.setMouseTracking(True)
@@ -332,19 +333,23 @@ def mousePressEvent(self, event):
332333
button = self.buttond.get(event.button())
333334
if button is not None and self.figure is not None:
334335
mods = self._mpl_modifiers()
336+
button = self._remap_darwin_button(button, mods)
337+
self._pressed_buttons[event.button()] = button
335338
MouseEvent("button_press_event", self,
336339
*self.mouseEventCoords(event),
337-
self._remap_darwin_button(button, mods),
340+
button,
338341
modifiers=mods,
339342
guiEvent=event)._process()
340343

341344
def mouseDoubleClickEvent(self, event):
342345
button = self.buttond.get(event.button())
343346
if button is not None and self.figure is not None:
344347
mods = self._mpl_modifiers()
348+
button = self._remap_darwin_button(button, mods)
349+
self._pressed_buttons[event.button()] = button
345350
MouseEvent("button_press_event", self,
346351
*self.mouseEventCoords(event),
347-
self._remap_darwin_button(button, mods), dblclick=True,
352+
button, dblclick=True,
348353
modifiers=mods,
349354
guiEvent=event)._process()
350355

@@ -361,9 +366,13 @@ def mouseReleaseEvent(self, event):
361366
button = self.buttond.get(event.button())
362367
if button is not None and self.figure is not None:
363368
mods = self._mpl_modifiers()
369+
# use the button remapped at the press time, so releasing Option
370+
# before the mouse button still reports the press time button
371+
button = self._pressed_buttons.pop(
372+
event.button(), self._remap_darwin_button(button, mods))
364373
MouseEvent("button_release_event", self,
365374
*self.mouseEventCoords(event),
366-
self._remap_darwin_button(button, mods),
375+
button,
367376
modifiers=mods,
368377
guiEvent=event)._process()
369378

0 commit comments

Comments
 (0)