Touchscreen input rotation using QEvent (evenfilter) - raspberry
-
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
-
@etiennedm Why don't you just use layouts?