Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to listen to QTouchEvent originating from a precision touch pad?



  • I have a Windows 10 laptop with a precision touchpad. I have been unsuccessfully trying to listen to QTouchEvent's originating from the touchpad. This is my code (Qt 5.9.4_patch2):

    #include <QApplication>
    #include "MyWindow.h"
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
    
        MyWindow window;
        window.show();
    
        return app.exec();
    }
    
    //MyWindow.h
    #pragma once
    
    #include <QtWidgets>
    
    class MyWindow : public QWindow
    {
        Q_OBJECT
    
    public: 
        MyWindow();
    
    protected:
        void touchEvent(QTouchEvent* e) override;
        bool event(QEvent* e) override;
    };
    
    //MyWindows.cpp
    #include "MyWindow.h"
    
    MyWindow::MyWindow()
        : QWindow()
    {
    }
    
    void MyWindow::touchEvent(QTouchEvent* e)
    {
        qDebug() << "Touch!!";
    }
    
    bool MyWindow::event(QEvent* e)
    {
        qWarning() << e->type(); 
        return QWindow::event(e);
    }
    

    The touch events never get triggered. I tried this too, but didn't work.

    Any ideas?


  • Qt Champions 2019

    @reylo-cu touchEvent is for touch events on a touch screen, not touch-pad. Touch pads work like a mouse. You should get mouse*Event() when using laptop touch pad.



  • @jsulm QTouchEvent class has the method *QTouchDevice QTouchEvent::device(). The device type QTouchDevice::TouchPad is supported by QT. So If I understand QTouchEvent documentation correctly, it should be possible.
    Access to the multitouch data from multi-touch-capable precision touchpads is possible in Windows via a low-level Window's API (e.g. GetRawInputData()). I was guessing/hoping that QTouchEvent was a higher-level, multiplatform solution on top of this.


Log in to reply