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())
{
std::cout<<"ScribbleArea received TouchEvent BEGIN";
inPut->accept();
handleEvent=true;
break;
//std::cout<<"ScribbleArea received TouchEvent UPDATE";
inPut->accept();
handleEvent=true;
break;
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;
std::cout<<"ScribbleArea received TabletEvent PRESS";
handleEvent=true;
break;
std::cout<<"ScribbleArea received TabletEvent RELEASE";
handleEvent=true;
break;
//std::cout<<"ScribbleArea received TabletEvent TabletEvent MOVE";
handleEvent=true;
break;
}
return handleEvent;
}
return true;
}
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;
}
To copy to clipboard, switch view to plain text mode
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
ScribbleArea received TouchEvent BEGIN
ScribbleArea received MouseEvent Press
ScribbleArea received TouchEvent END
ScribbleArea received MouseEvent RELEASE
To copy to clipboard, switch view to plain text mode
Consuming QTabletEvent by returning
handleEvent=true
handleEvent=true
To copy to clipboard, switch view to plain text mode
however works, no MouseEvent gets generated for already handled QTabletEvent?
Any help on this from you guys would be greatly appreciated
Bookmarks