Gestures in 4.7.1 behavior change

Fixing bugs sometimes means changing behavior. The gesture framework is still pretty fresh in Qt. It made its first appearance in Qt 4.6, but only now with Qt 4.7 is it going to be used big time. Sadly we found this bug too late to integrate it into Qt 4.7.0, but it seems important enough to be in 4.7.1.

The pinch gesture has a property that represents the zoom factor. This used to be initialized with the value 0.0 and the total scale factor would be the sum of all scale factors... just like rotations, where the angle is added up.

Well, we admit, that was a bit of a thinking mistake. Scaling is a multiplicative property. So from Qt 4.7.1 on this horrible mistake has been fixed to give you easy to use zooming. We think this is so important that it needs to be in Qt now, since it's a behavior change and we want to enable Qt to be used on devices.

So if you have a picture and you want to use two fingers to scale it, now all you have to do to make the picture scaling follow the fingers is to multiply the scaling by QPinchGesture::scaleFactor() and you are good :)

So what do we have in QPinchGesture?

  • scaleFactor - whenever you get a gesture event, you can multiply by this value to update your item.
  • totalScaleFactor - this is the scale factor since the beginning of the pinch - if you just care about the final scaling, this is what you want.

The commit in Qt's 4.7 branch is this one:

e6b2bb6d6a48e722311cd2c5fd86c015eab24b4d


Blog Topics:

Comments