PDA

View Full Version : Disable automatic event translation



kinglui987
10th December 2012, 10:52
Hey,

from the doc of QTouchEvent read this:



Event Delivery and Propagation
By default, QWidget::event() translates the first non-primary touch point in a QTouchEvent into a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not normally handle QTouchEvent. See below for information on some special considerations needed when doing this.


Has anyone an idea, how to disable the default behaviour of translating the fist non-primary touch point into a mouse event?

Further the docs explains:


Mouse Events and the Primary Touch Point

QTouchEvent delivery is independent from that of QMouseEvent. On some windowing systems, mouse events are also sent for the primary touch point. This means it is possible for your widget to receive both QTouchEvent and QMouseEvent for the same user interaction point. You can use the QTouchEvent::TouchPoint::isPrimary() function to identify the primary touch point.


How to interpret
On some windowing systems, mouse events are also sent for the primary touch point.How can i identify the way my OS(Win7) handles this?

Anyone any ideas on this?

Thanks for help

wysota
10th December 2012, 11:12
Has anyone an idea, how to disable the default behaviour of translating the fist non-primary touch point into a mouse event?
Reimplement QWidget::event() and if you detect a first touch event, don't call the default implementation but rather do something that suits your goals.


How can i identify the way my OS(Win7) handles this?
Make a test application and see for yourself.

kinglui987
13th December 2012, 12:38
Hey thanks for your help. Sorry for my late answer but unfortenately i did not get a notification from the forum.

I am still confronted with some problems.

I am attempting to hook an application and listen for touch an mouse events, simultaneously. I have a device that supports this. I am cathcing the events generated from my device, convert them to QEvents and post them in QT event loop using the postEvent(...) mechanism of QCoreApplication . Now am able to get the events simultaneously, but there still some problems.

The OS generates the mouse event for me (as usual), i am catching the touch events from my device and post them as described in Qt event loop.

However, it seems not to work properly, since sometimes two events get generated for the same input source (e.g. mouse or finger)

What i need is to identify the situation, when the OS generated an mouse event? Then, and only then, i fire my events, when there is touchinput registerd at my device. How would you build such a system?

Any suggestions, how build a stable architecture to manage this?

Thanks in advance

wysota
13th December 2012, 17:04
Maybe you should install an event filter on the application object? Then all events will go to the filter first before reaching the final object and you'll be able to decide what to do with them.

kinglui987
13th December 2012, 18:44
Hey,

that is exactly what i am currently doing. Maybe this is already the right way to do this.

Any other suggestions would be greatly appreciated ;-)

thanks so far...

kinglui987
24th January 2013, 13:57
Hey there,

it again me. Unfortunately i am again confronted with some problems. It seems that i never will understand QT event processing! I would like to understand, what QT does with the events. I installed an eventfilter on the qApp object. To my understandig, now alle events of all objects in the application go to the eventfilter object, right?

Imagine the following:
What if there are some Widgets in the application with setAttribute(Qt::WA_AcceptTouchEvents) called and some without this?
To my understanding, there will be differences in the event generated and catched by the installed eventfilter, depending on where the event was generated, so it makes it very hard to implement a generic eventhandling? Any suggestions on this?

Now back to the topic of this thread:

I simply could not achieve to disable to automatically generated MouseEvent for the first TouchEvent, as described in the docs. In the Examples of QT i modified the scribblearea.cpp in the fingerpaint example.
I deleted all specific eventhandlers and reimplemented the QWidget::event(QEvent *event) eventhandler.
Here is the code:



bool ScribbleArea::event(QEvent *event)
{
bool handleEvent = false;
QInputEvent* inPut = dynamic_cast<QInputEvent*>(event);
if(inPut)
{
switch (event->type())
{
case QEvent::TouchBegin:
std::cout<<"ScribbleArea received TouchEvent BEGIN";
inPut->accept();
handleEvent=true;
break;
case QEvent::TouchUpdate:
//std::cout<<"ScribbleArea received TouchEvent UPDATE";
inPut->accept();
handleEvent=true;
break;
case QEvent::TouchEnd:
std::cout<<"ScribbleArea received TouchEvent END";
inPut->accept();
handleEvent=true;
break;
case QEvent::MouseButtonPress:
std::cout<<"ScribbleArea received MouseEvent PRESS";
break;
case QEvent::MouseButtonRelease:
std::cout<<"ScribbleArea received MouseEvent RELEASE";
break;
case QEvent::TabletPress:
std::cout<<"ScribbleArea received TabletEvent PRESS";
handleEvent=true;
break;
case QEvent::TabletRelease:
std::cout<<"ScribbleArea received TabletEvent RELEASE";
handleEvent=true;
break;
case QEvent::TabletMove:
//std::cout<<"ScribbleArea received TabletEvent TabletEvent MOVE";
handleEvent=true;
break;
}
return handleEvent;
}
return true;
}


As the code illustrates i accept all touchevents and return handleEvent=true, which to my understand should mean there will be no further processing/propagation. Note, i do not call the base implementation.
However, the output is like this:


ScribbleArea received TouchEvent BEGIN
ScribbleArea received MouseEvent Press
ScribbleArea received TouchEvent END
ScribbleArea received MouseEvent RELEASE

Consuming QTabletEvent by returning
handleEvent=true however works, no MouseEvent gets generated for already handled QTabletEvent?

Any help on this from you guys would be greatly appreciated

patrasamiran
1st December 2014, 10:28
Hey experts,

Is there any solution for this problem for QTouchEvent? I am having the same problem.

Thanks,
Sam