QTouchEvent(Multitouch) Moving Items In The Scene



  • Hi,
    I am trying to implement Item Moving in my GraphicsView/GraphicsScene based application.The doc suggests that the function to capture touch events looks like this:(Sorry its long :-) )
    In case the touch point was moved ,I try to move the item just under the touched point but when I run the application and touch on top of an Item my events seem to be consumed by something else.(The test messageBox is not executed).

    I hope you more experienced folks could point out where I might be messing things up.May be there is another specific way to implement the moving of Items?

    Any input would be appreciated.

    NOTE:I know you can do this on an item basis but the application is designed in a way that makes this the least attractive option.

    @

    bool HBGraphicsView::viewportEvent(QEvent *event)
    {

    switch (event->type()) {
    case QEvent::TouchBegin:
    {
        //NOP
    }
    case QEvent::TouchUpdate:
    {
       //NOP
    }
    case QEvent::TouchEnd:
    {
    
        QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
    
        foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
             switch (touchPoint.state()) {
             case Qt::TouchPointStationary:
                 // don't do anything if this touch point hasn't moved
                 continue;
             //default:
    
             case Qt::TouchPointPressed:
             {
               //WE DO NOTHING HERE.... YET.
             }
             break;
    
    //HERE IS DONE ALL THE BULK OF THE MOVE FEATURE.
             case Qt::TouchPointMoved:
                 {
                   if(scene())
                   { 
                        //QMESSAGEBOX TO TEST THAT WE GET IN HERE.
                     //QMessageBox msgBox;
                     //msgBox.setText("GOT IN !!.");
                     //msgBox.exec&#40;&#41;;
    
                     QPoint point1(touchPoint.lastPos().x(),touchPoint.lastPos().y());
                     QPoint point2(touchPoint.pos().x(),touchPoint.pos().y());
                     QPointF mPoint1InScene=mapToScene(point1);//LAST POS
                     QPointF mPoint2InScene=mapToScene(point2);//CUR POS        
       
      if(scene()->itemAt(this->mapToScene(point2)))
                     {
       qreal dx=mPoint2InScene.x()-mPoint1InScene.x();
        qreal dy=mPoint2InScene.y()-mPoint1InScene.y();
                      scene()->itemAt(this->mapToScene(point2))->moveBy(dx,dy);
                    }
                        
                  }
                 }
                 break;
    
             case Qt::TouchPointReleased:
             {
                //WE DO NOTHING HERE.....YET.
             }
              break;
             }
         }
         break;
    }
    default:
        break;
    }
    return QGraphicsView::viewportEvent(event);
    

    }

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.