Results 1 to 2 of 2

Thread: Capturing Touch Screen events in MainWindow

  1. #1
    Join Date
    Jan 2013
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Capturing Touch Screen events in MainWindow

    Hi,

    i have already a Qt application implemented and running in embedded linux. I am trying to implement a sleep mode where the system cpu frequency goes into powersave mode and when the touch screen is touched it will bump up the CPU back to performance. you will note that the application works just fine right now so touch screen wise no problem.
    the problem i have is trying to capture QEvent::TouchBegin , QEvent::TouchUpdate, and QEvent::TouchEnd.

    I read several posts and tried the following. None is successful, i.e. it would print the first"I'm in..." message but apparently I am not getting the Touch evens i am waiting for.

    1. Override MainWindow event handler (MainWindow inherits QMainWindow)

    in constructor:
    setAttribute(Qt::WA_AcceptTouchEvents);


    bool MainWindow::event(QEvent *event)
    {
    printf("\r\n I'm in...");fflush(stdout);

    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    case QEvent::MouseButtonPress:
    printf("\r\n Touched!!!");fflush(stdout);
    break;

    default:
    break;
    }
    return QMainWindow::event(event); // I want to also get the button press events.
    }


    2. Create a TouchScreenFilter widget and install an eventfilter for the main window.

    main()
    {
    QApplication a (argc, argv);
    MainWindow w;
    TouchScreenFilter filter;

    w.installEventFilter(&filter);
    }



    #include <QWidget>
    #include <QEvent>

    class TouchScreenFilter : public QWidget
    {
    Q_OBJECT
    public:
    explicit TouchScreenFilter(QWidget *parent = 0);

    signals:

    public slots:

    protected:
    bool eventFilter(QObject *obj, QEvent *ev);
    };

    TouchScreenFilter::TouchScreenFilter(QWidget *parent) : QWidget(parent)
    {
    setAttribute(Qt::WA_AcceptTouchEvents);
    }

    bool TouchScreenFilter::eventFilter(QObject *obj, QEvent *event)
    {
    printf("\r\n I'm in...");fflush(stdout);

    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    printf("\r\n Touched!!!");fflush(stdout);
    break;

    default:
    break;
    }
    return QWidget::eventFilter(obj, event);
    }


    3. Override MainWindow eventFilter;

    protected:
    bool eventFilter(QObject*, QEvent*);


    bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    {
    printf("\r\n I'm in...");fflush(stdout);

    switch (event->type()) {
    case QEvent::TouchBegin:
    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    printf("\r\n Touched!!!");fflush(stdout);
    break;

    default:
    break;
    }
    return QMainWindow::eventFilter(obj, event);
    }


    Any Idea what is wrong? why am I not getting the actual Touch events??

    thanks,
    Daniel.

  2. #2
    Join Date
    Sep 2013
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Capturing Touch Screen events in MainWindow

    I have the same problem, Daniel you solved the problem?

Similar Threads

  1. Getting raw touch screen data.
    By mahdi75 in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2011, 08:42
  2. Touch Screen on Windows 7
    By briankibler in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2011, 14:15
  3. Replies: 0
    Last Post: 3rd March 2009, 15:38
  4. Touch screen
    By rchaitanya in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 19th January 2009, 13:40
  5. How to Implement the Touch Screen Events?
    By rchaitanya in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 25th December 2008, 09:44

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.