[Qt-interest] Mac: Two finger swipe and mouse wheel event

Richard Moe Gustavsen richard.gustavsen at nokia.com
Fri Feb 12 11:34:54 CET 2010


> When using the mouse wheel, I get values which are typically multiples
> of 8*15=120, while for the two finger swipe I now get multiples of 1.
> How can I handle this transparently? Would like to avoid a line such  
> as
> this:
>    if (abs(delta) < 120) delta *= 120

The API has not changed, but developers tend to assume that delta is  
always 120, which is true in many cases. But it can be both higher and  
lower. On Mac, Mighty Mouse, Magic Mouse and the trackpad has much  
higher granularity on the mouse wheel than standard mices. So to  
support smooth pixel-based scrolling like other native apps on Mac, we  
send out wheel events more often, with a corresponding lower delta.

So if you want the standard line-based scrolling, just accumulate  
delta until is reaches 120, then scroll one line (or do one swipe in  
your case, I guess). E.g.:

_delta += event->delta();
int linesToScroll = int(_delta/120);
_delta -= linesToScroll * 120;
if (linesToScroll > 0) { ... }

> Is this maybe related to the new QGesture infrastructure?

No.

-Richard



More information about the Qt-interest-old mailing list