Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
15 May 2024
The task was simple: Add double click to a push button - with the added bonus of it not emitting the normal clicked if there is a double click. OK, this sounds trivial, right? Well no, it wasn't entirely. To get it right you have to understand quite a bit of both signals/slots and the event system. This episode explains.
0:00 Introduction
0:22 A push button emitting double click - without emitting single click
1:44 Part 1 - Override mouseDoubleClickEvent
2:41 Part 2 - Introducing the crystal ball (a QTimer to postpone the single click signal)
4:58 Part 3 - Ensure up state is painted, but that the super class doesn't emit the signal - using QSignalBlocker
6:05 Part 4 - Understanding why we get the late "Thanks"
10:23 Part 5 - Simply use a flag to block the false event
11:56 Wouldn't it have been easier to implement a new button from scratch?
The example code showcased in this video is available here: https://github.com/KDABLabs/kdabtv/tree/master/Qt-Widgets-and-more/double-click-push-button
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI