[Qt-interest] QTimeLine from 0 to 100, to -100 and back to 0 ?

Oliver Demetz forenbeitraege at oliverdemetz.de
Fri Aug 21 11:24:29 CEST 2009


Solved,
just in case someone is interested:

class MyTimeLine : public QTimeLine
{
public:
	MyTimeLine ( int duration = 1000, QObject * parent = 0 )
	 : QTimeLine ( duration , parent ) {}

	qreal valueForTime(int msec) const
	{
		qreal d = (qreal) duration();

		if (msec < d/4)
		{
			return 4.0 * (qreal) msec / d;
		}
		else if(msec < 3*d/4)
		{
			return - 4*msec/d + 2;
		}
		else
		{
			return 4*msec/d - 4;
		}
	}
};

Then in my code:

MyTimeLine * tl = new MyTimeLine(2000,this);

// IMPORTANT: we want frame values between -100 and 100
tl->setFrameRange(0,100) // !!!!
Regards,
Oliver

Sean Harmer schrieb:
> Hi Oliver,
> 
> On Friday 21 Aug 2009 09:02:23 Oliver Demetz wrote:
>> Hi!
>>
>> QTimeLine seems to perfectly suited for the animation I want to realize,
>> but I just see a way to go elegantly "in one direction".
>>
>> I want to drive my animation first from state 0 to 100 - this should be
>> no problem. Then I would like to automatically drive the way down to
>> -100, and then back to the original state 0.
>>
>> So something like a complete sine period (2 PI) would be what I like.
>> Note that it would alos be fine to have linear trajectories, the sine
>> shape is not a must.
>>
>> Hope you can help me,
>>From the QTimeLine docs:
> 
> "For a custom timeline, you can reimplement valueForTime(), in which case 
> QTimeLine's curveShape property is ignored."
> 
> so I think that you need to reimplement the valueForTime() function and 
> interpret the value (in the range 0-1) slightly differently. i.e. Assume that 
> your start position is 0.5 which then increases up to 1 then down to 0 then 
> back to 0.5 again. i.e. It is a simple transformation from these values to 
> your desired animation sequence.
> 
> HTH,
> 
> Sean
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list