PDA

View Full Version : QPinchGesture positions are not defined in the widget coordinate system



embeddedmz
2nd September 2019, 12:33
Hello everybody,

First of all, I noticed that unlike Windows, under GNU/Linux, pinch gestures are not translated to mouse's wheel up/down events, so if I want to use zoom on a Qwt plot for example, I need to handle QGesture events in a Qt program.

I want to use the pinch gesture on a Qwt plot canavs so I can zoom (magnify) around a particular point on the plot. I have the code working with a mouse and I just need to modify it a little bit to make it work with the multitouch (under Ubuntu).

So I installed an event filter on the QwtPlot's canvas object to grab QGesture events and eventually called grabGesture(Qt::PinchGesture - solely on the canvas widget).

I noticed the following things :
QPinchGesture's startCenterPoint is always 0,0 whatever the pinch position.
QPinchGesture's centerPoint and lastCenterPoint are not defined in the widget coordinate system, for example when I start a pinch gesture on the left-top corner of the widget, they don't return a point close to 0,0, in fact they will return something like 583, 157. for the bottom right corner, I have something like 1298,603.

Is it a Qt bug ? I checked that mouse events (QMouseEvent::pos) are in the widget coordinate system !

I think I can translate the position to bypass this problem (QWidget::mapTo/mapFrom) but I need to find the widget defining gestures coordinate system... (main window ?)

UPDATE: Apparently, the positions returned by QPinchGesture::centerPoint/lastCenterPoint are relative to the screen coordinate system... I will try QWidget::mapFromGlobal...

embeddedmz
3rd September 2019, 12:09
In fact, the positions returned by QPinchGesture::centerPoint/lastCenterPoint are relative to the screen coordinate system and QWidget::mapFromGlobal did the trick !