December 25, 2010

endla.ravi endla.ravi
Lab Rat
17 posts

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…

2 replies

December 25, 2010

Immii Immii
Ant Farmer
233 posts

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.

December 25, 2010

VCsala VCsala
Lab Rat
339 posts

You have to use QPropertyAnimation class somehow like this snippet:

  1.  QPropertyAnimation *animation = new QPropertyAnimation(yourObject, "geometry");
  2.  animation->setDuration(10000);
  3.  animation->setStartValue(QRect(p1.x, p1.y, w, h));
  4.  animation->setEndValue(QRect(p2.x, p2.y, w, h));
  5.  
  6.  animation->start();

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

 
  ‹‹ qt custom widgets propertis are not getting updated properly in Qt designer      [SOLVED] State Design Pattern ››

You must log in to post a reply. Not a member yet? Register here!