[Qt-interest] How to differentiate itemClicked() and itemDoubleClicked() signals
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Tue Jul 7 15:57:37 CEST 2009
Santhosh Y wrote on Tuesday, July 07, 2009 3:14 PM:
> Hi,
>
> I implemented a custom treewidget and connected the itemClicked() and
> itemDoubleClicked() to some slots in it.
> When an item is double clicked i have observed that, itemClicked()
> signal is also being emitted.
That's absolutely correct! It is because at the time of the first mouse-click the system/Qt does not know yet whether another click within the "double-click interval" (which by the way is a user setting in the OS system settings!) will follow, making it a "double-click". Usually that interval is around 200 ms, but if your grandma is sitting in front of the computer, she might have set the interval to 1 second ;)
(On Windows, check your System Settings -> Mouse - Most likely you will get a mouse vendor specific dialog where there should be a slider somewhere, setting that "double-click interval").
> I want to differentiate between a single and double click signals
> correctly.
So if you really need to differentiate single vs double-click, then the only solution you have is to use a single-shot timer with dt > "double-click interval", which you start in the itemClicked() slot. If the itemDoubleClicked() slot is called later on, you reset the timer and handle the double-click. Otherwise the timer fires and in the timer slot you handle the single-click.
> Please suggest me how to do this.
In other words, you *don't* handle the mouse-click in the itemClicked() slot yet, until you are sure what kind of click you are dealing with: in the itemDoubleClicked() slot or in the timer slot.
The tricky part of this is to figure out (in a system/window manager independent way) the user double-click interval; to my knowledge Qt does not provide an API for that yet (I might be wrong though). But this is left as an exercise for the reader ;)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list