Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTouchEvent(Multitouch) Moving Items In The Scene

QTouchEvent(Multitouch) Moving Items In The Scene

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    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);
    

    }

    @

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved