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. Qt 5.12 Unable To Get Touch Events

Qt 5.12 Unable To Get Touch Events

Scheduled Pinned Locked Moved Unsolved General and Desktop
touchtouch screentouchscreenmouse pressmousepressevent
4 Posts 3 Posters 1.4k 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.
  • D Offline
    D Offline
    duhanayan
    wrote on last edited by duhanayan
    #1

    I am working on very complicated Qt project. I have a GL screen on my app and I want it to be zoomed in/out with touch screen moves. But unfortunetly I can't handle touch events.

    I added a line to accept touch events to my constructor.

    setAttribute(Qt::WA_AcceptTouchEvents, true);
    

    And here is my event function under protected that I print events that happened.

    class MyWidget: public QGLWidget
    {
    	Q_OBJECT
    protected:
    		bool event(QEvent *event) override
    	{
    	    // Print the event type
    	    qDebug() << "Event Type: " << event->type();
    
    	    if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
    	        QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
    
    	        QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
    
    	        if (touchPoints.count() == 2) {
    	            QTouchEvent::TouchPoint touchPoint1 = touchPoints.at(0);
    	            QTouchEvent::TouchPoint touchPoint2 = touchPoints.at(1);
    
    	            qDebug() << "Touch 1: " << touchPoint1.pos();
    	            qDebug() << "Touch 2: " << touchPoint2.pos();
    	        }
    	        return true;
    	    }
    	    return QWidget::event(event);
    	}
    

    And I added this line to my main function:

    app.setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents);
    

    When I try to touch from touch screen, what printed in output is QEvent::MouseButtonPress.

    So anyone know what to do, I would be grateful.

    Axel SpoerlA 1 Reply Last reply
    0
    • D duhanayan

      I am working on very complicated Qt project. I have a GL screen on my app and I want it to be zoomed in/out with touch screen moves. But unfortunetly I can't handle touch events.

      I added a line to accept touch events to my constructor.

      setAttribute(Qt::WA_AcceptTouchEvents, true);
      

      And here is my event function under protected that I print events that happened.

      class MyWidget: public QGLWidget
      {
      	Q_OBJECT
      protected:
      		bool event(QEvent *event) override
      	{
      	    // Print the event type
      	    qDebug() << "Event Type: " << event->type();
      
      	    if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
      	        QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
      
      	        QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
      
      	        if (touchPoints.count() == 2) {
      	            QTouchEvent::TouchPoint touchPoint1 = touchPoints.at(0);
      	            QTouchEvent::TouchPoint touchPoint2 = touchPoints.at(1);
      
      	            qDebug() << "Touch 1: " << touchPoint1.pos();
      	            qDebug() << "Touch 2: " << touchPoint2.pos();
      	        }
      	        return true;
      	    }
      	    return QWidget::event(event);
      	}
      

      And I added this line to my main function:

      app.setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents);
      

      When I try to touch from touch screen, what printed in output is QEvent::MouseButtonPress.

      So anyone know what to do, I would be grateful.

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @duhanayan said in Qt 5.12 Unable To Get Touch Events:

      AA_SynthesizeTouchForUnhandledMouseEvents

      That is a known bug, unfortunately.
      It won´t be fixed in 5.12, but everything works in Qt 6.

      Software Engineer
      The Qt Company, Oslo

      Christian EhrlicherC 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        @duhanayan said in Qt 5.12 Unable To Get Touch Events:

        AA_SynthesizeTouchForUnhandledMouseEvents

        That is a known bug, unfortunately.
        It won´t be fixed in 5.12, but everything works in Qt 6.

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Axel-Spoerl So you can close the bug :)

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        Axel SpoerlA 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          @Axel-Spoerl So you can close the bug :)

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          Done, Sir :-)
          I was just not sure, whether the fix happened in 5.15 or 6.2.
          The latter it is.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          2

          • Login

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