Hi,
I want to simulate QTouchEvent using Mouseevents. I mean I don't have a touch screen, but want to simulate touch behavior using Mouse. Is this possible and how?
Thanks
D
Hi,
I want to simulate QTouchEvent using Mouseevents. I mean I don't have a touch screen, but want to simulate touch behavior using Mouse. Is this possible and how?
Thanks
D
When a mouse click event occures, eat it and send a touch event.
dpatel (17th August 2010)
I can easily eat the MouseEvent but have real hard times in posting the touch event.
bool MouseTouchFilter::eventFilter(QObject *obj, QEvent *event)
{
...
else if (event->type() == QEvent::MouseButtonPress){
QMouseEvent *mEvent = static_cast<QMouseEvent *>(event);
qDebug("Ate mousepress");
QTouchEvent *tev=new QTouchEvent(QEvent::TouchBegin,QTouchEvent::TouchS creen);
// QCoreApplication::sendEvent(obj,tev);
return QObject::eventFilter(obj, tev);
}
Forgot to ask for help...
Can you help me? I always get a nice SEGFAULT..after posting the TouchEvent.
Fabio
Added after 33 minutes:
Eventually this code seems to work as a general structure but fails in filtering the event
else if (event->type() == QEvent::MouseButtonPress){
QMouseEvent *mEvent = static_cast<QMouseEvent *>(event);
qDebug("Ate mousepress");
QTouchEvent *tEvent=new QTouchEvent(QEvent::TouchBegin,QTouchEvent::TouchS creen);
return QObject::eventFilter(obj, tEvent);
}
Once I catch the event on the object grabbing the mouse event i get back QEvent::MouseButtonPress instead of QEvent::TouchBegin, so say event 2 instead of 192.
imageWidget->setAttribute(Qt::WA_AcceptTouchEvents);
has been called just after istantiating the Widget.
Last edited by fabioferrario; 21st March 2011 at 15:23.
Just a suggestion to try, haven't tested it myself. Try usingto allow completion of the processing of the mouseEvent.Qt Code:
To copy to clipboard, switch view to plain text mode
Last edited by thru; 22nd March 2011 at 09:56.
Thanks ,
this is something I tried, as you see in the code I used SendEvent() and also tried postEvent().
The issue I have right now is the TouchEvent berin transformed in MouseEvent.
The Filter sends the TouchEvent and the Widget gets a MouseEvent.
I took care in the Widget to accept the TouchEvents but still no joy
this->setAttribute(Qt::WA_AcceptTouchEvents);
this->setAttribute(Qt::WA_NoMousePropagation);
this->setAttribute(Qt::WA_TouchPadAcceptSingleTouchEven ts);
Just for anyone that is still wondering how, you can use the QTest::touchEvent framework. I've implemented a custom touch simulation by catching the mouse events and generating the .press(), .move() and .release() events.
As per documentation, the events are sent when the object goes out of scope so I call it like:
Qt Code:
QTest::touchEvent(widget).press(0,pos); ... QTest::touchEvent(widget).move(0,pos);To copy to clipboard, switch view to plain text mode
Bookmarks