Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Touch Event Handling Issue: Positional Offset and Poor Finger Response on Resistive Screen
Qt 6.11 is out! See what's new in the release blog

Qt Touch Event Handling Issue: Positional Offset and Poor Finger Response on Resistive Screen

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 219 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Ramanujum
    wrote last edited by
    #1

    Hello Qt Community,

    I am currently working on an embedded project using the Allwinner A133 processor with the following configuration:

    Operating System: Ubuntu 18.04
    Kernel: Linux 4.9
    Qt Version: Qt 5.12.12 (Qt Widgets)
    Touch Type: Resistive touchscreen

    For touch detection, I am using the following implementation:
    void MainWindow::enableTouchOnAllWidgets(QWidget *widget)
    {
    if (!widget) return;
    widget->setAttribute(Qt::WA_AcceptTouchEvents);
    foreach (QWidget child, widget->findChildren<QWidget>()) {
    child->setAttribute(Qt::WA_AcceptTouchEvents);
    }
    }

    bool MainWindow::event(QEvent *event)
    {
    if (event->type() == QEvent::TouchBegin ||
    event->type() == QEvent::TouchUpdate ||
    event->type() == QEvent::TouchEnd)
    {
    QTouchEvent touchEvent = static_cast<QTouchEvent>(event);
    if (touchEvent->touchPoints().isEmpty()) {
    event->accept();
    return true;
    }

        if (event->type() == QEvent::TouchBegin)
        {
            touchProcessing = false;
        }
    
        if (event->type() == QEvent::TouchEnd)
        {
            if (touchProcessing)
            {
                event->accept();
                return true;
            }
    
            QPoint globalPos = touchEvent->touchPoints().first().screenPos().toPoint();
    
            QWidget *widget = QApplication::widgetAt(globalPos);
    
            if (widget)
            {
                QWidget *current = widget;
                while (current)
                {
                    QPushButton *button = qobject_cast<QPushButton*>(current);
                    if (button && button->isEnabled() && button->isVisible())
                    {
                        touchProcessing = true;
                        emit button->clicked();
                        event->accept();
                        return true;
                    }
                    current = current->parentWidget();
                }
    
                QPoint targetPos = widget->mapFromGlobal(globalPos);
    
                QMouseEvent press(QEvent::MouseButtonPress,
                    targetPos,
                    Qt::LeftButton,
                    Qt::LeftButton,
                    Qt::NoModifier);
                QApplication::sendEvent(widget, &press);
    
                QMouseEvent release(QEvent::MouseButtonRelease,
                    targetPos,
                    Qt::LeftButton,
                    Qt::LeftButton,
                    Qt::NoModifier);
                QApplication::sendEvent(widget, &release);
    
                touchProcessing = true;
            }
        }
    
        event->accept();
        return true;
    }
    
    return QWidget::event(event);
    

    }
    However, I am experiencing a positional offset issue with the touch input. For buttons located at the bottom of the display, the touch response is shifted approximately 1 cm downward—meaning the button only responds when I touch about 1 cm below its actual position. Similarly, for buttons on the right side, the touch response is shifted approximately 1 cm to the right. The same behavior is observed for other directions as well.

    Additionally, I am facing another issue with the resistive touchscreen: touch input using a fingernail is detected accurately, but touch input using a finger is inconsistent or unreliable.

    Could you please help me understand the possible causes of these issues and suggest solutions to resolve them?

    Thank you.

    jsulmJ 1 Reply Last reply
    0
    • R Ramanujum

      Hello Qt Community,

      I am currently working on an embedded project using the Allwinner A133 processor with the following configuration:

      Operating System: Ubuntu 18.04
      Kernel: Linux 4.9
      Qt Version: Qt 5.12.12 (Qt Widgets)
      Touch Type: Resistive touchscreen

      For touch detection, I am using the following implementation:
      void MainWindow::enableTouchOnAllWidgets(QWidget *widget)
      {
      if (!widget) return;
      widget->setAttribute(Qt::WA_AcceptTouchEvents);
      foreach (QWidget child, widget->findChildren<QWidget>()) {
      child->setAttribute(Qt::WA_AcceptTouchEvents);
      }
      }

      bool MainWindow::event(QEvent *event)
      {
      if (event->type() == QEvent::TouchBegin ||
      event->type() == QEvent::TouchUpdate ||
      event->type() == QEvent::TouchEnd)
      {
      QTouchEvent touchEvent = static_cast<QTouchEvent>(event);
      if (touchEvent->touchPoints().isEmpty()) {
      event->accept();
      return true;
      }

          if (event->type() == QEvent::TouchBegin)
          {
              touchProcessing = false;
          }
      
          if (event->type() == QEvent::TouchEnd)
          {
              if (touchProcessing)
              {
                  event->accept();
                  return true;
              }
      
              QPoint globalPos = touchEvent->touchPoints().first().screenPos().toPoint();
      
              QWidget *widget = QApplication::widgetAt(globalPos);
      
              if (widget)
              {
                  QWidget *current = widget;
                  while (current)
                  {
                      QPushButton *button = qobject_cast<QPushButton*>(current);
                      if (button && button->isEnabled() && button->isVisible())
                      {
                          touchProcessing = true;
                          emit button->clicked();
                          event->accept();
                          return true;
                      }
                      current = current->parentWidget();
                  }
      
                  QPoint targetPos = widget->mapFromGlobal(globalPos);
      
                  QMouseEvent press(QEvent::MouseButtonPress,
                      targetPos,
                      Qt::LeftButton,
                      Qt::LeftButton,
                      Qt::NoModifier);
                  QApplication::sendEvent(widget, &press);
      
                  QMouseEvent release(QEvent::MouseButtonRelease,
                      targetPos,
                      Qt::LeftButton,
                      Qt::LeftButton,
                      Qt::NoModifier);
                  QApplication::sendEvent(widget, &release);
      
                  touchProcessing = true;
              }
          }
      
          event->accept();
          return true;
      }
      
      return QWidget::event(event);
      

      }
      However, I am experiencing a positional offset issue with the touch input. For buttons located at the bottom of the display, the touch response is shifted approximately 1 cm downward—meaning the button only responds when I touch about 1 cm below its actual position. Similarly, for buttons on the right side, the touch response is shifted approximately 1 cm to the right. The same behavior is observed for other directions as well.

      Additionally, I am facing another issue with the resistive touchscreen: touch input using a fingernail is detected accurately, but touch input using a finger is inconsistent or unreliable.

      Could you please help me understand the possible causes of these issues and suggest solutions to resolve them?

      Thank you.

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

      @Ramanujum Why are you doing all this? QPushButton already supports touch events.

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ramanujum
        wrote last edited by
        #3

        In my case it is not working after this only my qt ui is reacting for touch event and added #include<QTouchEvent>

        jsulmJ 1 Reply Last reply
        0
        • R Ramanujum

          In my case it is not working after this only my qt ui is reacting for touch event and added #include<QTouchEvent>

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote last edited by
          #4

          @Ramanujum Not sure I understand. You get touch events in your Qt app, right?

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

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ramanujum
            wrote last edited by
            #5

            Yes i got but not perfectly i got , i am getting my buttons in offset places

            1 Reply Last reply
            0
            • sbelaS Offline
              sbelaS Offline
              sbela
              wrote last edited by
              #6

              You have to calibrate the screen?! I think.

              I would like!

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Ramanujum
                wrote last edited by
                #7

                I did ts_calibrate many times and in ts_test also working only

                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