|
GLWidget 不支持触控的,改了一下,处理QTouchEvent,但是效果不对,做不到跟MFC的WM_TOUCH一致,求教怎么处理触控???
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- {
- auto e = static_cast<QTouchEvent*>(event);
- auto pts = e->touchPoints();
- Q_ASSERT(!pts.empty());
- osg::ref_ptr<osgGA::GUIEventAdapter> osgEvent;
- for( int i = 0; i < pts.size(); ++i)
- {
- if(pts[i].state() & Qt::TouchPointPressed)
- {
- if(!osgEvent) {
- osgEvent = _gw->getEventQueue()->touchBegan(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_BEGAN, pts[i].screenPos().x(), pts[i].screenPos().y());
- }
- else {
- osgEvent->addTouchPoint(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_BEGAN, pts[i].screenPos().x(), pts[i].screenPos().y());
- }
- }
- else if(pts[i].state() & Qt::TouchPointMoved)
- {
- if(!osgEvent) {
- osgEvent = _gw->getEventQueue()->touchMoved(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_MOVED, pts[i].screenPos().x(), pts[i].screenPos().y());
- }
- else {
- osgEvent->addTouchPoint(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_MOVED, pts[i].screenPos().x(), pts[i].screenPos().y());
- }
- }
- else if(pts[i].state() & Qt::TouchPointReleased)
- {
- // No double tap detection with RAW TOUCH Events, sorry.
- if(!osgEvent) {
- osgEvent = _gw->getEventQueue()->touchEnded(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_ENDED, pts[i].screenPos().x(), pts[i].screenPos().y(), 1);
- }
- else {
- osgEvent->addTouchPoint(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_ENDED, pts[i].screenPos().x(), pts[i].screenPos().y());
- }
- }
- }
- }return true;
复制代码 |
|