Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to handle a release event for the second finger in QOpenGLWindow
Qt 6.11 is out! See what's new in the release blog

How to handle a release event for the second finger in QOpenGLWindow

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 1 Posters 362 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.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by 8Observer8
    #1

    I'm trying to create an Android game controller to make a Super Mario clone, just to learn programming and practice:

    0bb11f66-7e4e-42e8-92b1-849d8f8a3962-image.png

    The next problem stopped me. I touch the screen with my first finger. While holding the first finger, I touch and release the second finger. I expect that when I release the second finger, the Qt Creator debug console should display:

    TouchUpdate  2
    TouchUpdate  1
    
    void OpenGLWindow::touchEvent(QTouchEvent *event)
    {
        switch (event->type())
        {
            case QEvent::TouchBegin:
            {
                qDebug() << "TouchBegin";
                event->accept();
                break;
            }
            case QEvent::TouchUpdate:
            {
                qDebug() << "TouchUpdate " << event->points().length();
                break;
            }
        }
    }
    

    But only the first few releases work normally. Then the releases work with delays. And after a few more releases I see:

    TouchUpdate  2
    TouchUpdate  2
    

    Minimal example: release-event-of-the-second-finger-qt6-cpp.zip

    Cross-ref: https://stackoverflow.com/questions/78096690/how-to-handle-a-release-event-for-the-second-finger-in-qopenglwindow

    1 Reply Last reply
    0
    • 8Observer88 Offline
      8Observer88 Offline
      8Observer8
      wrote on last edited by 8Observer8
      #2

      Solution: https://doc.qt.io/qt-6/qeventpoint.html#State-enum

      void OpenGLWindow::touchEvent(QTouchEvent *event)
      {
          switch (event->type())
          {
              case QEvent::TouchBegin:
              {
                  qDebug() << "TouchBegin";
                  event->accept();
                  break;
              }
              case QEvent::TouchUpdate:
              {
                  if (event->points().length() > 1)
                  {
                      QEventPoint::State firstState = event->points()[0].state();
                      QEventPoint::State secondState = event->points()[1].state();
                      if (firstState == QEventPoint::State::Released ||
                          secondState == QEventPoint::State::Released)
                      {
                          qDebug() << "Released";
                      }
                  }
                  break;
              }
          }
      }
      
      1 Reply Last reply
      0
      • 8Observer88 8Observer8 has marked this topic as solved on

      • Login

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