I have a QGraphicsScene with QGraphicsItems. I have reimplemented the sceneEvent function and handle multi-touch.
The problem is that randomly I get invalid values out of this section:
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
const QTouchEvent::TouchPoint &p0 = touchPoints.first();
Gives the following debug information (not all the time):
Debug: TouchUpdate: p0.scenePos(): QPointF(489.76, 160.71) :
Debug: TouchUpdate: p0.startPos(): QPointF(-8.62078e+14, 1.83351e+15)
I have no idea why startPos() should be a random value like that. Any suggestions?
Are you blindly casting events or using a switch-case statement as below ?
bool MyItem::sceneEvent(QEvent *event)
{
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
//Remember to accept the event too
event->accept();
break;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.