How to move an object in a specified path...

  • Hi..

    how can i move an object(may be a dotted point) on a line.

    I have seen the colliding mice example,but could not understand the code.

    Suppose i have

    QLine *line= new QLine(p1,p2); //where p1 and p2 are QPoint objects.

    Now is there any way to move my object on that line?..If yes how?

    Thanking you in advance...

  • There are couple of examples available which does similar type animation, have you tried having look of those? at least two I remember "Easing Curve" and "path stroking" Hope this should give you enough insight how to do it.

  • You have to use QPropertyAnimation class somehow like this snippet:

    @ QPropertyAnimation *animation = new QPropertyAnimation(yourObject, "geometry");
    animation->setStartValue(QRect(p1.x, p1.y, w, h));
    animation->setEndValue(QRect(p2.x, p2.y, w, h));


    where p1 and p2 is your points and w and h are the width and the height of the object you plan to move.

Log in to reply

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