Results 1 to 6 of 6

Thread: How to simulate QTouchEvent using mouse

  1. #1
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to simulate QTouchEvent using mouse

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to simulate QTouchEvent using mouse

    When a mouse click event occures, eat it and send a touch event.

  3. The following user says thank you to tbscope for this useful post:

    dpatel (17th August 2010)

  4. #3
    Join Date
    Mar 2011
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to simulate QTouchEvent using mouse

    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.

  5. #4
    Join Date
    Mar 2009
    Posts
    39
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to simulate QTouchEvent using mouse

    Just a suggestion to try, haven't tested it myself. Try using
    Qt Code:
    1. QCoreApplication::postEvent
    To copy to clipboard, switch view to plain text mode 
    to allow completion of the processing of the mouseEvent.
    Last edited by thru; 22nd March 2011 at 09:56.

  6. #5
    Join Date
    Mar 2011
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to simulate QTouchEvent using mouse

    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);

  7. #6
    Join Date
    Jul 2015
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to simulate QTouchEvent using mouse

    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:
    1. QTest::touchEvent(widget).press(0,pos);
    2. ...
    3. QTest::touchEvent(widget).move(0,pos);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 15th March 2010, 14:49
  2. Multiple widgets to receive QTouchEvent
    By jlin in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2009, 04:37
  3. Simulate QMenu behavior
    By Remenic in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2009, 19:48
  4. Replies: 5
    Last Post: 17th July 2009, 12:17
  5. how to Simulate the keyboard press
    By duduqq in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2008, 16:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.