Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use TouchPoint class present in QTouchEvent class
Forum Updated to NodeBB v4.3 + New Features

How to use TouchPoint class present in QTouchEvent class

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BhanuKiranChaluvadiB Offline
    BhanuKiranChaluvadiB Offline
    BhanuKiranChaluvadi
    wrote on last edited by BhanuKiranChaluvadi
    #1

    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 "http://www.codeprogress.com/cpp/libraries/qt/qtCaptureMouseMove.php"

    I slightly modified the code to incorporate touch events

    #include<QWindow>
    #include<QTouchEvent>
    #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()));
      }
    

    }

    Errors:
    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.

    jsulmJ 1 Reply Last reply
    0
    • BhanuKiranChaluvadiB BhanuKiranChaluvadi

      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 "http://www.codeprogress.com/cpp/libraries/qt/qtCaptureMouseMove.php"

      I slightly modified the code to incorporate touch events

      #include<QWindow>
      #include<QTouchEvent>
      #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()));
        }
      

      }

      Errors:
      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @BhanuKiranChaluvadi TouchPoint is a type not a variable!
      Please check documentation http://doc.qt.io/qt-5/qtouchevent.html
      You need to call http://doc.qt.io/qt-5/qtouchevent.html#touchPoints
      It returns a list of touch points:

      QList<QTouchEvent::TouchPoint>
      

      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) {
          ...
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      BhanuKiranChaluvadiB 1 Reply Last reply
      0
      • jsulmJ jsulm

        @BhanuKiranChaluvadi TouchPoint is a type not a variable!
        Please check documentation http://doc.qt.io/qt-5/qtouchevent.html
        You need to call http://doc.qt.io/qt-5/qtouchevent.html#touchPoints
        It returns a list of touch points:

        QList<QTouchEvent::TouchPoint>
        

        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) {
            ...
        }
        
        BhanuKiranChaluvadiB Offline
        BhanuKiranChaluvadiB Offline
        BhanuKiranChaluvadi
        wrote on last edited by
        #3

        @jsulm Thank you

        1 Reply Last reply
        0
        • BhanuKiranChaluvadiB Offline
          BhanuKiranChaluvadiB Offline
          BhanuKiranChaluvadi
          wrote on last edited by
          #4

          I am sharing the code. might be help someone

          I have 3 Files:
          mainWinodw.h
          mainWindow.cpp
          main.cpp

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

          #include <QMainWindow>
          #include <QEvent>

          namespace Ui {
          class MainWindow;
          }

          class MainWindow : public QMainWindow
          {
          Q_OBJECT

          public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();
          bool event(QEvent *e)
          {
          qInfo("Event Entered");
          switch(e->type())
          {
          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;
          default:
          qInfo("No touch Event occured");
          return QWidget::event(e);
          }
          }

          private:
          Ui::MainWindow *ui;
          };

          #endif // MAINWINDOW_H

          //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
          ui->setupUi(this);
          setAttribute(Qt::WA_AcceptTouchEvents, true);
          }

          MainWindow::~MainWindow()
          {
          delete ui;
          }
          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

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

          return a.exec();
          

          }
          //////////////////////////////////////////////////////////////////////////////

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved