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. Touchscreen input rotation using QEvent (evenfilter) - raspberry

Touchscreen input rotation using QEvent (evenfilter) - raspberry

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
touchscreenraspberrylinuxfbeventfilterqevent
2 Posts 2 Posters 1.6k 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.
  • E Offline
    E Offline
    etiennedm
    wrote on 28 Jun 2016, 10:22 last edited by
    #1

    Hello everyone,
    I am using raspberry 3 with qt 5.6 (cross compilation). I had some issues with the touchscreen (robopeak 2.8") to rotate it, but after applying a patch to qt, I am able to rotate the screen via the linux framebuffer (see http://borkedlabs.com/2015/06/01/qt5-linuxfb-rotation-for-lcds/).
    But now, the view is 90-rotated, and the input events stayed as they were. Which means I have to tap on the bottom left to activate my button on the top left...

    I tried to filter the QEvent from my touchscreen, and apply a rotation to them, but without success... I don't understand, I think I have catched all the event.
    I used the eventFilter method, and because I don't know which event calls the "clicked()" signal on all my button, I catch mouse and touch events :

    mainwindow.h

    protected:
        bool eventFilter(QObject *obj, QEvent *ev);
    

    mainwindow.cpp

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        qApp->installEventFilter(this);
    ...
    }
    
    bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
    {
        if (ev->type() == QEvent::MouseButtonPress || ev->type() == QEvent::MouseButtonRelease || ev->type() == QEvent::MouseMove) {
    
            QMouseEvent *tmp_ev = (QMouseEvent*) ev;
    
            QPointF tmp_pos = tmp_ev->windowPos();
    //        qDebug() << tmp_pos.x() << "  -  " << tmp_pos.y() ;
            qreal tmp_v = tmp_pos.x();
            tmp_pos.setX(tmp_pos.y() * 240 / 320);
            tmp_pos.setY(320 - tmp_v * 320 / 240);
    //        qDebug() << tmp_pos.x() << "  -  " << tmp_pos.y() ;
            QMouseEvent *new_ev = new QMouseEvent(tmp_ev->type(), tmp_pos, tmp_pos, tmp_pos, tmp_ev->button(), tmp_ev->buttons(), tmp_ev->modifiers());
            ev = (QEvent*) new_ev;
    //        qDebug() << ">> " << ((QMouseEvent*)ev)->pos().x() << "  -  " << ((QMouseEvent*)ev)->pos().y();
            return QMainWindow::eventFilter(obj, ev);
        }
        else if(ev->type() == QEvent::Enter || ev->type() == QEvent::Leave)
        {
            QEnterEvent *tmp_ev = (QEnterEvent*) ev;
            qDebug() << ev->type() << " : " << ((QEnterEvent*)ev)->localPos().x() << "  -  " << ((QEnterEvent*)ev)->localPos().y();
    
            QPointF tmp_pos = tmp_ev->localPos();
            qreal tmp_v = tmp_pos.x();
            tmp_pos.setX(tmp_pos.y() * 240 / 320);
            tmp_pos.setY(320 - tmp_v * 320 / 240);
            QEnterEvent *new_ev = new QEnterEvent(tmp_pos, tmp_pos, tmp_pos);
            ev = (QEvent*) new_ev;
            qDebug() << ev->type() << " : " << ((QEnterEvent*)ev)->localPos().x() << "  -  " << ((QEnterEvent*)ev)->localPos().y();
    
            return QMainWindow::eventFilter(obj, ev);
    
        }
        else if(ev->type() == QEvent::HoverMove)
        {
            QMouseEvent *tmp_ev = (QMouseEvent*) ev;
            QPointF tmp_pos = tmp_ev->windowPos();
            tmp_pos.setX(340);
            tmp_pos.setY(340);
            QMouseEvent *new_ev = new QMouseEvent(tmp_ev->type(), tmp_pos, tmp_pos, tmp_pos, tmp_ev->button(), tmp_ev->buttons(), tmp_ev->modifiers());
            ev = (QEvent*) new_ev;
            return QMainWindow::eventFilter(obj, ev);
        }
        else if(ev->type() == QEvent::TouchBegin || ev->type() == QEvent::TouchUpdate || ev->type() == QEvent::TouchEnd)
        {
            QTouchEvent *tmp_ev = (QTouchEvent*) ev;
            //qDebug() << ev->type() << " : " << ((QTouchEvent*)ev)->touchPoints().last().pos().x() << "  -  " << ((QTouchEvent*)ev)->touchPoints().last().pos().y();
            QList<QTouchEvent::TouchPoint> tmp_touchPoints = tmp_ev->touchPoints();
            for(int i=0; i<tmp_touchPoints.count() ; i++)
            {
                QPointF tmp_pos = tmp_touchPoints[i].pos();
                qreal tmp_v = tmp_pos.x();
                tmp_pos.setX(tmp_pos.y() * 240 / 320);
                tmp_pos.setY(320 - tmp_v * 320 / 240);
    
                tmp_touchPoints[i].setPos(tmp_pos);
            }
    
    
            QTouchEvent *new_ev = new QTouchEvent(tmp_ev->type(), Q_NULLPTR, tmp_ev->modifiers(), tmp_ev->touchPointStates(), tmp_touchPoints);
            ev = (QEvent*) new_ev;
            for(int i=0; i<tmp_touchPoints.count() ; i++)
            {
                //qDebug() << ev->type() << " : " << ((QTouchEvent*)ev)->touchPoints()[i].pos().x() << "  -  " << ((QTouchEvent*)ev)->touchPoints()[i].pos().y();
            }
    
            return QMainWindow::eventFilter(obj, ev);
        }
        else
            qDebug() << "Event : " << ev->type() ;
    
        // Make sure the rest of events are handled
        return QMainWindow::eventFilter(obj, ev);
    }
    

    So I applied a transformation on all those events, but even if the qDebug() seems to show that all they are well changed, it changes nothing on the screen.... I still have to tap on the bottom left to activate my top left button...

    Maybe I'm doing something wrong on the events ? I don't catch the right ones ?
    Any idea ?

    Thanks

    J 1 Reply Last reply 28 Jun 2016, 10:27
    0
    • E etiennedm
      28 Jun 2016, 10:22

      Hello everyone,
      I am using raspberry 3 with qt 5.6 (cross compilation). I had some issues with the touchscreen (robopeak 2.8") to rotate it, but after applying a patch to qt, I am able to rotate the screen via the linux framebuffer (see http://borkedlabs.com/2015/06/01/qt5-linuxfb-rotation-for-lcds/).
      But now, the view is 90-rotated, and the input events stayed as they were. Which means I have to tap on the bottom left to activate my button on the top left...

      I tried to filter the QEvent from my touchscreen, and apply a rotation to them, but without success... I don't understand, I think I have catched all the event.
      I used the eventFilter method, and because I don't know which event calls the "clicked()" signal on all my button, I catch mouse and touch events :

      mainwindow.h

      protected:
          bool eventFilter(QObject *obj, QEvent *ev);
      

      mainwindow.cpp

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          qApp->installEventFilter(this);
      ...
      }
      
      bool MainWindow::eventFilter(QObject *obj, QEvent *ev)
      {
          if (ev->type() == QEvent::MouseButtonPress || ev->type() == QEvent::MouseButtonRelease || ev->type() == QEvent::MouseMove) {
      
              QMouseEvent *tmp_ev = (QMouseEvent*) ev;
      
              QPointF tmp_pos = tmp_ev->windowPos();
      //        qDebug() << tmp_pos.x() << "  -  " << tmp_pos.y() ;
              qreal tmp_v = tmp_pos.x();
              tmp_pos.setX(tmp_pos.y() * 240 / 320);
              tmp_pos.setY(320 - tmp_v * 320 / 240);
      //        qDebug() << tmp_pos.x() << "  -  " << tmp_pos.y() ;
              QMouseEvent *new_ev = new QMouseEvent(tmp_ev->type(), tmp_pos, tmp_pos, tmp_pos, tmp_ev->button(), tmp_ev->buttons(), tmp_ev->modifiers());
              ev = (QEvent*) new_ev;
      //        qDebug() << ">> " << ((QMouseEvent*)ev)->pos().x() << "  -  " << ((QMouseEvent*)ev)->pos().y();
              return QMainWindow::eventFilter(obj, ev);
          }
          else if(ev->type() == QEvent::Enter || ev->type() == QEvent::Leave)
          {
              QEnterEvent *tmp_ev = (QEnterEvent*) ev;
              qDebug() << ev->type() << " : " << ((QEnterEvent*)ev)->localPos().x() << "  -  " << ((QEnterEvent*)ev)->localPos().y();
      
              QPointF tmp_pos = tmp_ev->localPos();
              qreal tmp_v = tmp_pos.x();
              tmp_pos.setX(tmp_pos.y() * 240 / 320);
              tmp_pos.setY(320 - tmp_v * 320 / 240);
              QEnterEvent *new_ev = new QEnterEvent(tmp_pos, tmp_pos, tmp_pos);
              ev = (QEvent*) new_ev;
              qDebug() << ev->type() << " : " << ((QEnterEvent*)ev)->localPos().x() << "  -  " << ((QEnterEvent*)ev)->localPos().y();
      
              return QMainWindow::eventFilter(obj, ev);
      
          }
          else if(ev->type() == QEvent::HoverMove)
          {
              QMouseEvent *tmp_ev = (QMouseEvent*) ev;
              QPointF tmp_pos = tmp_ev->windowPos();
              tmp_pos.setX(340);
              tmp_pos.setY(340);
              QMouseEvent *new_ev = new QMouseEvent(tmp_ev->type(), tmp_pos, tmp_pos, tmp_pos, tmp_ev->button(), tmp_ev->buttons(), tmp_ev->modifiers());
              ev = (QEvent*) new_ev;
              return QMainWindow::eventFilter(obj, ev);
          }
          else if(ev->type() == QEvent::TouchBegin || ev->type() == QEvent::TouchUpdate || ev->type() == QEvent::TouchEnd)
          {
              QTouchEvent *tmp_ev = (QTouchEvent*) ev;
              //qDebug() << ev->type() << " : " << ((QTouchEvent*)ev)->touchPoints().last().pos().x() << "  -  " << ((QTouchEvent*)ev)->touchPoints().last().pos().y();
              QList<QTouchEvent::TouchPoint> tmp_touchPoints = tmp_ev->touchPoints();
              for(int i=0; i<tmp_touchPoints.count() ; i++)
              {
                  QPointF tmp_pos = tmp_touchPoints[i].pos();
                  qreal tmp_v = tmp_pos.x();
                  tmp_pos.setX(tmp_pos.y() * 240 / 320);
                  tmp_pos.setY(320 - tmp_v * 320 / 240);
      
                  tmp_touchPoints[i].setPos(tmp_pos);
              }
      
      
              QTouchEvent *new_ev = new QTouchEvent(tmp_ev->type(), Q_NULLPTR, tmp_ev->modifiers(), tmp_ev->touchPointStates(), tmp_touchPoints);
              ev = (QEvent*) new_ev;
              for(int i=0; i<tmp_touchPoints.count() ; i++)
              {
                  //qDebug() << ev->type() << " : " << ((QTouchEvent*)ev)->touchPoints()[i].pos().x() << "  -  " << ((QTouchEvent*)ev)->touchPoints()[i].pos().y();
              }
      
              return QMainWindow::eventFilter(obj, ev);
          }
          else
              qDebug() << "Event : " << ev->type() ;
      
          // Make sure the rest of events are handled
          return QMainWindow::eventFilter(obj, ev);
      }
      

      So I applied a transformation on all those events, but even if the qDebug() seems to show that all they are well changed, it changes nothing on the screen.... I still have to tap on the bottom left to activate my top left button...

      Maybe I'm doing something wrong on the events ? I don't catch the right ones ?
      Any idea ?

      Thanks

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 28 Jun 2016, 10:27 last edited by
      #2

      @etiennedm Why don't you just use layouts?

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

      1 Reply Last reply
      0

      1/2

      28 Jun 2016, 10:22

      • Login

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