Problem with touch gestures handling.



  • Hi everyone,

    I have three different touch screens:

    1. the official Raspberry Pi touch screen (https://www.raspberrypi.org/blog/the-eagerly-awaited-raspberry-pi-display/) ,
    2. 7 inch capacitive touch screen from Waveshare (http://www.waveshare.com/wiki/7inch_HDMI_LCD_(B))
    3. and touch monitor Dell S2240T (http://www.dell.com/ed/business/p/dell-s2240t/pd) .

    I would like to implement some touch gestures, but it looks like handling events with Qt (5.5.0) is different on different touch screens.
    On the official Raspberry Pi touch screen mouse events doesn't come to the event handler method, but on the other touch screens mouse events appear. This causes the button doesn't respond to tap gestures.

    I wrote simple application to demonstrate this problem.

    touchscreen_test.pro

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = touchscreen_test
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    #include <QFile>
    #include <QTextStream>
    #include <QDateTime>
    
    void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    {
        Q_UNUSED(context);
    
        QString time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
        QString txt = QString("[%1] ").arg(time);
    
        int t = type;
        switch (t)
        {
        case QtDebugMsg:
            txt += QString("{Debug} \t %1").arg(msg);
            break;
        case QtWarningMsg:
            txt += QString("{Warning} \t %1").arg(msg);
            break;
        case QtCriticalMsg:
            txt += QString("{Critical} \t %1").arg(msg);
            break;
        case QtFatalMsg:
            txt += QString("{Fatal} \t %1").arg(msg);
            abort();
            break;
        }
    
        QFile outFile("touchscreen_test.log");
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
    
        QTextStream textStream(&outFile);
        textStream << txt << endl;
    }
    
    int main(int argc, char *argv[])
    {
        qInstallMessageHandler(messageHandler);
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private slots:
        void on_pushButton_clicked();
    
    private:
        bool event(QEvent *);
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        setAttribute(Qt::WA_AcceptTouchEvents);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    bool MainWindow::event(QEvent *ev)
    {
        int t = ev->type();
        if(t == QEvent::MouseButtonPress
                || t == QEvent::MouseButtonDblClick
                || t == QEvent::MouseButtonPress
                || t == QEvent::MouseButtonRelease
                || t == QEvent::TouchBegin
                || t == QEvent::TouchCancel
                || t == QEvent::TouchEnd
                || t == QEvent::TouchUpdate) {
            qDebug()<<ev->type();
        }
        if(t ==QEvent::TouchBegin)
        {
            ev->accept();
            return true;
        }
        else
            return QWidget::event(ev);
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        qDebug()<<"[MainWindow::on_pushButton_clicked] pushButton_clicked!";
    }
    

    mainwindow.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>426</width>
        <height>397</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralWidget">
       <layout class="QVBoxLayout" name="verticalLayout">
        <item>
         <widget class="QPushButton" name="pushButton">
          <property name="text">
           <string>PushButton</string>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QStatusBar" name="statusBar"/>
     </widget>
     <layoutdefault spacing="6" margin="11"/>
     <resources/>
     <connections/>
    </ui>
    

    The first touch screen (the official Raspberry Pi) gives this output:
    ...
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchBegin)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:55] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:56] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchEnd)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchBegin)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchEnd)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchBegin)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:57] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:58] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:58] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:44:58] {Debug} QEvent::Type(TouchUpdate)
    ...

    The second and third touch screen (Waveshare, Dell) gives this output:
    ...
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchBegin)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(MouseButtonPress)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:49] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchEnd)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(MouseButtonRelease)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchBegin)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    [2016-06-17 13:49:50] {Debug} QEvent::Type(TouchUpdate)
    ...

    Is there any way to enable mouse events for the official Raspberry Pi touch screen?



  • Hi Kiug,

    I have tried your source code. I am having waveshare 10" screen with raspberry pi. Which runs a kiosk qt application. When I touch on screen it returns me the following logs. here is the link for product http://www.waveshare.com/wiki/10.1inch_HDMI_LCD

    Mouse button pressed
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch Update
    Touch End
    Mouse button release

    It couldn't handling QPushbutton's any signal while touch. So, if you know anything related to this issue then kindly help me to come-out from it.

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.