May 16, 2012

feldifux feldifux
Ant Farmer
79 posts

MouseArea & Multitouch

 

Hi,
I would like to move several QML items independently by using MouseAreas. However, a second touch does not generate a new pressed-event but a positionChanged for the first touch. So this is what I tried, which should allow dragging the 2 rectangles independently with 2 fingers:

  1. Item {
  2. width: 400
  3. height: 400
  4.  
  5.     Rectangle {
  6.         x:30
  7.         y: 30
  8.         width: 100
  9.         height: 100
  10.         color: "blue"
  11.  
  12.         MouseArea {
  13.             anchors.fill: parent
  14.             drag.target: parent
  15.         }
  16.     }
  17.  
  18.     Rectangle {
  19.         x:parent.width-130
  20.         y: parent.height-130
  21.         width: 100
  22.         height: 100
  23.         color: "red"
  24.  
  25.         MouseArea {
  26.             anchors.fill: parent
  27.             drag.target: parent
  28.         }
  29.     }
  30. }

As far as I have seen in QWidget::event() in qwidget.cpp of gui kernel, the touchEvents should get converted automatically to MouseEvents. I am using the QmlApplicationViewer for displaying my qml files, and also setting Qt::WA_AcceptTouchEvents did not change this behavior.

Is there a way I could use the MouseArea with independent touches, or which other approach could I use?

13 replies

May 17, 2012

agocs agocs
Lab Rat
13 posts

MouseArea is inherently mouse event based and won’t work very well with multi touch. In Qt 5 you could just use MultiPointTouchArea instead of MouseArea. If this is 4.x then there is no ready-made QML element available so you either handle touch events in C++ or experiment with the (possibly obsolete) TouchArea element from http://qt.gitorious.org/qt-labs/qml-toucharea

May 17, 2012

feldifux feldifux
Ant Farmer
79 posts

Thanks!
So I’ll implement my own item in C++ handling touch events, which has the same API as MouseArea so it is easy to use existing code with it. Because from a QML-user perspective, I would like to have an item where I dont have to care how many touchpoints there are, but only if there was a touch in the area I defined. So like a MultiPointTouchArea with a single touchPoint.

May 20, 2012

aabc aabc
Robot Herder
257 posts

Does MultiPointTouchArea works well with single touch ?

May 23, 2012

agocs agocs
Lab Rat
13 posts
aabc wrote:
Does MultiPointTouchArea works well with single touch ?

Yes, its feature set is however somewhat different and lower-level when compared to MouseArea. In most single-touch cases MouseArea is still the preferred solution.

May 23, 2012

aabc aabc
Robot Herder
257 posts

Isn’t MouseArea designed for Mouse and not for Touch ?
When you say “preferred solution” you mean performance or programming ?

May 23, 2012

alexleutgoeb alexleutgoeb
Lab Rat
29 posts

MouseArea only listens for MouseEvents and therefore is designed for mouse related input methods, that’s right.

Symbian for example however sends for each first touch (primary touch) a related mouse event, and touch events received from a qwidget get converted to mouse events too (if the touches are not primary).

So if you’re only interested in single touch events the MouseArea is the easiest way to go (and therefore the “preferred solution”?), if you require advanced multitouch recognition you’ve to look at PinchArea, TouchArea or your own custom implementation, as Christian probably does for now.

Alex

May 23, 2012

aabc aabc
Robot Herder
257 posts

My problem is that The MouseArea works fine with stylus but poor with fingrer touch.
Did you encounter that problem ?

May 23, 2012

alexleutgoeb alexleutgoeb
Lab Rat
29 posts

Didn’t have any problems so far in general. Which platform are you testing on? And what’s your definition of “poor”? ;) Are the events in-accurate? Are you losing your drag events?

May 23, 2012

aabc aabc
Robot Herder
257 posts

My target is Embedded Linux over Freescale IMX53.
In poor I mean that QML elements like flickable and lists are dragged in a very bad way when I use finger comparing to stylus (very unaccurate and hard to drag)

May 23, 2012

alexleutgoeb alexleutgoeb
Lab Rat
29 posts

I’ve no experience with that but I’m pretty sure your problem isn’t related to the Qt Quick MouseArea implementation. (I would guess the hardware drivers or probably the hardware itself is rather inaccurate with handling touch events?)

May 23, 2012

aabc aabc
Robot Herder
257 posts

Did you use Qt Quick over touch devices ?

May 23, 2012

alexleutgoeb alexleutgoeb
Lab Rat
29 posts

Only on Symbian/Meego ones, there it is working like intended…

May 23, 2012

agocs agocs
Lab Rat
13 posts

alexleutgoeb wrote:
MouseArea only listens for MouseEvents and therefore is designed for mouse related input methods, that’s right.

So if you’re only interested in single touch events the MouseArea is the easiest way to go (and therefore the “preferred solution”?), if you require advanced multitouch recognition you’ve to look at PinchArea, TouchArea or your own custom implementation, as Christian probably does for now.

Exactly. With MultiPointTouchArea many traditional mouse/single-touch tasks like click or double click detection, simple dragging support, etc. will become more complicated while with MouseArea these are available out of the box. MultiPointTouchArea is not meant to replace MouseArea, it rather complements it.

 
  ‹‹ Qt::QueuedConnection from QML      virtual keyboard doesn’t open although it exists when focusing TextInput or TextEdit elements. ››

You must log in to post a reply. Not a member yet? Register here!