Important: Please read the Qt Code of Conduct -

How to use TouchPoint class present in QTouchEvent class

  • Hi,
    I have a windows tablet and i am trying to display position of my touch. I am using QT Creator

    I choose an example(Mouse move) from this link ""

    I slightly modified the code to incorporate touch events

    #include <QApplication>
    #include <QMainWindow>
    #include <QHBoxLayout>
    #include <QLabel>

    class myLabel : public QLabel , QWindow
    myLabel() {} //constructor copied from example
    ~myLabel() {} //copied

      void touchEvent(QTouchEvent *event)
         this->setText("X:"+QString::number(event->TouchPoint.lastPos().x())+"-- Y:"+QString::number(event->TouchPoint.lastPos().y()));


    error: C2273: 'function-style cast': illegal as right side of '->' operator
    error: C2228: left of '.lastPos' must have class/struct/union
    error: C2228: left of '.x' must have class/struct/union

    I am trying to create a simple touch based example. I am not
    "class myLabel : public QLabel , QWindow"
    is the way to get the touch events.

    If there is any simpler example online kindly let me know.

  • Lifetime Qt Champion

    @BhanuKiranChaluvadi TouchPoint is a type not a variable!
    Please check documentation
    You need to call
    It returns a list of touch points:


    Then you can iterate over all points and print them out (a touch event can contain more than one event - multitouch):

    QList<QTouchEvent::TouchPoint> points = event->touchPoints();
    for (const QTouchEvent::TouchPoint& point : points) {

  • @jsulm Thank you

  • I am sharing the code. might be help someone

    I have 3 Files:

    /////////////////////////////////////// mainWinodw.h /////////////////////////////////////////////////////////////
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QEvent>

    namespace Ui {
    class MainWindow;

    class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);
    bool event(QEvent *e)
    qInfo("Event Entered");
    case QEvent::TouchBegin:
    qInfo("TouchBegin Event occured");
    return true;
    case QEvent::TouchUpdate:
    qInfo("TouchUpdate Event occured");
    return true;
    case QEvent::TouchEnd:
    qInfo("TouchEnd Event occured");
    return true;
    qInfo("No touch Event occured");
    return QWidget::event(e);

    Ui::MainWindow *ui;

    #endif // MAINWINDOW_H


    ////////////////////////////////mainWinodw.cpp ////////////////////////////////////////////////////////////////////
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
    setAttribute(Qt::WA_AcceptTouchEvents, true);

    delete ui;

    //////////////////////////////////////////main.cpp /////////////////////////////////////////////////////////////////////////
    #include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    MainWindow w;;

    return a.exec();


Log in to reply