Skip to content

Qt5 Backend: dblclick is always False on 'mouse_release_event' #4001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
diogolr opened this issue Jan 14, 2015 · 5 comments · Fixed by #14188
Closed

Qt5 Backend: dblclick is always False on 'mouse_release_event' #4001

diogolr opened this issue Jan 14, 2015 · 5 comments · Fixed by #14188
Labels
Milestone

Comments

@diogolr
Copy link

diogolr commented Jan 14, 2015

Simple as that... The dblclick flag is always False on mouse_release_event because the mouseDoubleClickEvent only call button_press_event, as follow:

backend_qt5.py

def mouseDoubleClickEvent(self, event):
        x = event.pos().x()
        # flipy so y=0 is bottom of canvas
        y = self.figure.bbox.height - event.pos().y()
        button = self.buttond.get(event.button())
        if button is not None:
            FigureCanvasBase.button_press_event(self, x, y,
                                                button, dblclick=True)
        if DEBUG:
            print('button doubleclicked:', event.button())

Can we fix this with a button_release_event call, also?

@diogolr diogolr changed the title dblclick is on 'mouse_release_event' dblclick is False on 'mouse_release_event' Jan 14, 2015
@diogolr diogolr changed the title dblclick is False on 'mouse_release_event' Qt5 Backend: dblclick is False on 'mouse_release_event' Jan 14, 2015
@diogolr diogolr changed the title Qt5 Backend: dblclick is False on 'mouse_release_event' Qt5 Backend: dblclick is always False on 'mouse_release_event' Jan 14, 2015
@tacaswell tacaswell added this to the v1.5.x milestone Jan 14, 2015
@tacaswell
Copy link
Member

Can you please put that in a pull request? That is the easiest way to review the changes and makes sure you get credit for your work.

@petehuang
Copy link
Contributor

Code is largely the same as OP, see here https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_qt5.py#L271

@diogolr would you like to help us improve this functionality with a PR?

@tacaswell
Copy link
Member

What is the use for a release event on a double click? Looking at https://doc.qt.io/qt-4.8/qwidget.html#mouseDoubleClickEvent it looks like Qt does not have a notion of 'double click release'. As mpl does not have separate notion of double click events, we just tack the flag on.

It also says that the widgets will get the standard button press and button release events in addition to the double click events. Experimentally, this second click is converted to the double click by Qt so we only see 2 press events (the first one + double-click) and 2 release events (the second of which is delayed until the mouse is actually released (ex press-release-press-wait-release)).

I think mpl should take the same position as Qt, it is the responsibility of user code to keep track of if a release event came from the second click of a double click.

If we do make this change, it should be done across all of the GUI backends (not just Qt).


import datetime
import matplotlib.pyplot as plt
plt.ion()


def cb1(event):
    print('p', datetime.datetime.now().isoformat(), event.dblclick)


def cb2(event):
    print('r', datetime.datetime.now().isoformat(), event.dblclick)


fig, ax = plt.subplots()

fig.canvas.mpl_connect('button_press_event', cb1)
fig.canvas.mpl_connect('button_release_event', cb2)
p 2017-01-08T16:04:54.745000 False
r 2017-01-08T16:04:55.135865 False

p 2017-01-08T16:04:57.704899 False
r 2017-01-08T16:04:57.752425 False
p 2017-01-08T16:04:57.840663 True
r 2017-01-08T16:04:57.972945 False

p 2017-01-08T16:05:01.531077 False
r 2017-01-08T16:05:01.621503 False
p 2017-01-08T16:05:01.687119 False
r 2017-01-08T16:05:05.140481 False

p 2017-01-08T16:05:06.040959 False
r 2017-01-08T16:05:06.109972 False
p 2017-01-08T16:05:06.186492 True
r 2017-01-08T16:05:08.067290 False

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@holy-motors
Copy link

Can you confirm this is still an issue?

@timhoffm
Copy link
Member

timhoffm commented May 11, 2019

FigureCanvasBase.button_relase_event does not have a notion of double click. The same is True for Qt.

In Qt a double click produces the event sequence:

press
release
doubleClick
release

The same is true for matplotlib; with the only difference, that Qt has it's own event type "doubleClick" but matplotlib only uses a flag in the MouseEvent. The dblclick flag is unused for events other than press.

This is not a bug but standard behavior. Will be documented via #14188.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants