#include "multitouchscreenfix.h" #include #include void MultiTouchScreenFix::install(QWidget *wgt) { new MultiTouchScreenFix(wgt); } bool MultiTouchScreenFix::eventFilter(QObject *o, QEvent *e) { QEvent::Type eventType = e->type(); const bool isTouchEvent = eventType == QEvent::TouchBegin || eventType == QEvent::TouchCancel || eventType == QEvent::TouchUpdate || eventType == QEvent::TouchEnd; if(isTouchEvent) { QTouchEvent *te = static_cast(e); // Touch points that are updated in the event are not leftovers for(auto &tp: te->touchPoints()) leftoverTouchPoints_.remove(tp.id()); // If there are some leftover touch points that are not reported in the event, send an event reporting them as released - this is the core of this workaround if(!leftoverTouchPoints_.isEmpty()) { for(QTouchEvent::TouchPoint &p: leftoverTouchPoints_) p.setState(Qt::TouchPointReleased); QTouchEvent ee(QEvent::TouchEnd, te->device(), te->modifiers(), Qt::TouchPointReleased, QList(leftoverTouchPoints_.begin(), leftoverTouchPoints_.end())); QApplication::sendEvent(o, &ee); } // Again fill leftover touch points for(auto &tp: te->touchPoints()) { if(tp.state() == Qt::TouchPointReleased) leftoverTouchPoints_.remove(tp.id()); else leftoverTouchPoints_[tp.id()] = tp; } } return false; } MultiTouchScreenFix::MultiTouchScreenFix(QWidget *wgt) : QObject(wgt) { wgt->installEventFilter(this); }