[PySide] Double click handling or retaining ownership of mouse events

Marco Grubert grubertm at hotmail.com
Wed Apr 8 18:49:47 CEST 2020

Thank you for pointing out the doubleClickInterval, Cristián - that looks helpful.
I should clarify that I want to keep the existing implementation for the single click events, and only change behavior when a user double-clicks.
That's where things are going bad. I am trying to call through to the base class for single-clicks but it expects a QMouseEvent and the one I got earlier has apparently been deleted on the C++ side.

From: PySide <pyside-bounces at qt-project.org> on behalf of Cristián Maureira-Fredes <Cristian.Maureira-Fredes at qt.io>
Sent: Wednesday, April 8, 2020 5:54 AM
To: pyside at qt-project.org <pyside at qt-project.org>
Subject: Re: [PySide] Double click handling or retaining ownership of mouse events

Hello Marco,

On 4/8/20 2:01 AM, Marco Grubert wrote:
> Hello,
> I am trying to handle single and double-click events differently in a
> QToolButton.
>  From what I have read in forums, Qt does not filter out single click
> events when a double click occurs, in other words there will always be a
> mousePressEvent emitted even if it's actually a double-click. The
> recommended approach in C++ appears to be launching a timer and
> deferring single click handling.
> a) If there is a better approach, please let me know!
> b) I tried the implementation below, but in the timerExpired function I
> get the dreaded "Internal C++ object (PySide2.QtGui.QMouseEvent) already
> deleted" error. I guess storing it in a member variable is insufficient?
> (snip)

I would rather base the implementation on the 'doubleClickInterval()'
for the QTimer, and use a boolean variable to handle when it's
single or double click, so you can then implement

You can check an implementation here:

Not sure if it's better than your approach,
but at least it's simpler IMHO.

Let me know if that's enough, otherwise, we can try to address the
C++ issues you are having in your code.


Dr. Cristian Maureira-Fredes
R&D Manager

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin

Geschäftsführer: Mika Pälsi,
Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
PySide mailing list
PySide at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20200408/89fdffb2/attachment.html>

More information about the PySide mailing list