QTimeLine Class Reference

[QtCore module]

该QTimeLine类提供了一个时间表来控制动画。More…

继承QObject

Types

  • enum CurveShape { EaseInCurve, EaseOutCurve, EaseInOutCurve, LinearCurve, SineCurve, CosineCurve }
  • enum Direction { Forward, Backward }
  • enum State { NotRunning, Paused, Running }

Methods

  • __init__ (self, int duration = 1000, QObject parent = None)
  • int currentFrame (self)
  • int currentTime (self)
  • float currentValue (self)
  • CurveShape curveShape (self)
  • Direction direction (self)
  • int duration (self)
  • QEasingCurve easingCurve (self)
  • int endFrame (self)
  • int frameForTime (self, int msec)
  • int loopCount (self)
  • resume (self)
  • setCurrentTime (self, int msec)
  • setCurveShape (self, CurveShape shape)
  • setDirection (self, Direction direction)
  • setDuration (self, int duration)
  • setEasingCurve (self, QEasingCurve curve)
  • setEndFrame (self, int frame)
  • setFrameRange (self, int startFrame, int endFrame)
  • setLoopCount (self, int count)
  • setPaused (self, bool paused)
  • setStartFrame (self, int frame)
  • setUpdateInterval (self, int interval)
  • start (self)
  • int startFrame (self)
  • State state (self)
  • stop (self)
  • timerEvent (self, QTimerEvent event)
  • toggleDirection (self)
  • int updateInterval (self)
  • float valueForTime (self, int msec)

Qt Signals

  • void finished ()
  • void frameChanged (int)
  • void stateChanged (QTimeLine::State)
  • void valueChanged (qreal)

Detailed Description

该QTimeLine类提供了一个时间表来控制动画。

这是最常用的定期调用插槽,一个动画图形用户界面控制。你可以通过传递它的持续时间以毫秒为单位QTimeLine的构造函数构造一个时间表。时间线的持续时间描述了多久动画将运行。然后,通过调用设置一个合适的框架范围setFrameRange( ) 。最后连接frameChanged()信号到一个合适的插槽,你想在动画(例如, setValue方法( )的小工具QProgressBar) 。当您进行呼叫start( ) , QTimeLine将进入运行状态,并开始发光frameChanged( )定期,造成你的widget的连接属性的值从低端长到你的框架范围的上限,并以稳定的速度。你可以通过调用指定的更新间隔setUpdateInterval( ) 。完成后, QTimeLine进入NotRunning态,并发射finished( ) 。

例如:

  1. ...
  2. progressBar = new [QProgressBar]($docs-qprogressbar.html)(this);
  3. progressBar->setRange(0, 100);
  4. // Construct a 1-second timeline with a frame range of 0 - 100
  5. QTimeLine *timeLine = new QTimeLine(1000, this);
  6. timeLine->setFrameRange(0, 100);
  7. connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
  8. // Clicking the push button will start the progress bar animation
  9. pushButton = new [QPushButton](qpushbutton.html)(tr("Start animation"), this);
  10. connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start()));
  11. ...

您还可以使用QTimeLine与Graphics View framework为动画。该QGraphicsItemAnimation类实现的动画QGraphicsItems有一个时间表。

默认情况下,时间线运行一次,从一开始接近尾声,在这你必须调用start()再次从开始重新启动。若要使时间循环,可以调用setLoopCount( ) ,传递时代的时间表应该在完成之前运行的次数。方向也可以改变,导致在时间轴向后运行,通过调用setDirection( ) 。您也可以暂停及恢复的时间线,而它的运行通过调用setPaused( ) 。对于交互式的控制,setCurrentTime()函数被提供,其直接设置时间线的时间位置。虽然最有用NotRunning状态(例如,连接到一个valueChanged()中的信号QSlider,),该函数可以在任何时候调用。

在框架接口是标准的部件有用的,但QTimeLine可用于控制任何类型的动画。 QTimeLine的心脏在于valueForTime( )函数,它产生一个_value_0和1之间一个给定的时间。这个值通常是用来描述一个动画,其中0是动画的第一步骤,和1是最后一步的步骤。在运行时, QTimeLine通过调用生成0和1之间的值valueForTime()和发射valueChanged( ) 。默认情况下,valueForTime( )适用的插值算法来生成这些值。您可以从一组预定义的时间线算法通过调用选择setCurveShape( ) 。

请注意,默认情况下, QTimeLine使用EaseInOut曲线形状,它提供了一个值,生长缓慢,然后稳步增长,终于慢慢地成长。对于自定义的时间轴,你可以重新实现valueForTime() ,在这种情况QTimeLine的curveShape属性被忽略。


Type Documentation

  1. QTimeLine.CurveShape

这个枚举变量描述的默认形状QTimeLine的价值曲线。默认的,形状是EaseInOutCurve 。该曲线定义的值,并在时间轴之间的关系。

Constant Value Description
QTimeLine.EaseInCurve 0 该值开始缓慢增长,然后在速度增加。
QTimeLine.EaseOutCurve 1 该值开始稳步增长,然后慢慢结束。
QTimeLine.EaseInOutCurve 2 该值开始缓慢增长,然后稳步运行,然后再次生长缓慢。
QTimeLine.LinearCurve 3 该值线性增长(例如,如果持续时间为1000毫秒,在时间的价值500毫秒为0.5 ) 。
QTimeLine.SineCurve 4 价值增长正弦。
QTimeLine.CosineCurve 5 价值增长cosinusoidally 。

See also setCurveShape( ) 。

  1. QTimeLine.Direction

这个枚举变量描述时间轴的方向时,Running状态。

Constant Value Description
QTimeLine.Forward 0 时间轴的当前时间随时间(即从0到接近尾声/时间移动) 。
QTimeLine.Backward 1 随着时间(即从底/持续时间和对0移动)时间轴的当前时间减少。

See also setDirection( ) 。

  1. QTimeLine.State

这个枚举变量描述时间轴的状态。

Constant Value Description
QTimeLine.NotRunning 0 时间轴没有运行。这是初始状态QTimeLine,和国家QTimeLine重新进入时完成。当前的时间,框架和价值保持不变,直至setCurrentTime( )被调用时,或者时间线是通过调用启动start( ) 。
QTimeLine.Paused 1 时间轴暂停(即暂停) 。调用setPaused (假)将恢复时间表活动。
QTimeLine.Running 2 时间线运行。而控制是在事件循环,QTimeLine将定期更新其当前的时间,发光valueChanged()和frameChanged( )在适当的时候。

See also state()和stateChanged( ) 。


Method Documentation

  1. QTimeLine.__init__ (self, int duration = 1000, QObject parent = None)

parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。

构造一个带有时间线的持续时间duration毫秒。parent被传递给QObject的构造。默认持续时间为1000毫秒。

  1. int QTimeLine.currentFrame (self)

返回对应于当前的时间框架。

See also currentTime( )frameForTime()和setFrameRange( ) 。

  1. int QTimeLine.currentTime (self)
  1. float QTimeLine.currentValue (self)

返回对应于当前时间的值。

See also valueForTime()和currentFrame( ) 。

  1. CurveShape QTimeLine.curveShape (self)

  1. Direction QTimeLine.direction (self)

[

  1. int QTimeLine.duration (self)

]($docs-qtimeline.html#Direction-enum)

  1. QEasingCurve QTimeLine.easingCurve (self)

[

  1. int QTimeLine.endFrame (self)

返回端框架,它是对应于时间线(即对于其当前值是1帧)的端部的框架。

]($docs-qeasingcurve.html)

See also setEndFrame()和setFrameRange( ) 。

  1. int QTimeLine.frameForTime (self, int msec)

返回对应于时间帧msec。此值是使用的开始和结束帧的线性插值,基于由返回的值计算出valueForTime( ) 。

See also valueForTime()和setFrameRange( ) 。

  1. int QTimeLine.loopCount (self)
  1. QTimeLine.resume (self)

这种方法也是一个Qt槽与C + +的签名void resume()

从当前时间恢复的时间表。QTimeLine将重新进入运行状态,一旦进入事件循环,它会更新其当前的时间,框架和价值定期进行。

在对比start( ) ,这个函数不重新启动的时间线将恢复之前。

See also start( )updateInterval( )frameChanged()和valueChanged( ) 。

  1. QTimeLine.setCurrentTime (self, int msec)

这种方法也是一个Qt槽与C + +的签名void setCurrentTime(int)

  1. QTimeLine.setCurveShape (self, CurveShape shape)
  1. QTimeLine.setDirection (self, Direction direction)
  1. QTimeLine.setDuration (self, int duration)
  1. QTimeLine.setEasingCurve (self, QEasingCurve curve)
  1. QTimeLine.setEndFrame (self, int frame)

设置结束帧,这是对应于时间线(即对于其当前值是1帧)的端部的框架,以frame

See also endFrame( )startFrame()和setFrameRange( ) 。

  1. QTimeLine.setFrameRange (self, int startFrame, int endFrame)

设置时间轴的帧计数器开始在startFrame以及端部和endFrame。对于每个时间值,QTimeLine将找到相应的帧,当你调用currentFrame()或frameForTime()通过内插,使用的返回值valueForTime( ) 。

当在运行状态下,QTimeLine还发出了frameChanged( )信号时,帧的变化。

See also startFrame( )endFrame( )start()和currentFrame( ) 。

  1. QTimeLine.setLoopCount (self, int count)
  1. QTimeLine.setPaused (self, bool paused)

这种方法也是一个Qt槽与C + +的签名void setPaused(bool)

If paused诚然,在时间轴暂停,造成QTimeLine进入暂停状态。没有更新将被通知,直至start()或setPaused (假)被调用。如果paused是假的,时间轴恢复并继续它。

See also state()和start( ) 。

  1. QTimeLine.setStartFrame (self, int frame)

设置开始帧,这是对应于时间线(即对于该电流值是0帧)的开始,到该帧frame

See also startFrame( )endFrame()和setFrameRange( ) 。

  1. QTimeLine.setUpdateInterval (self, int interval)
  1. QTimeLine.start (self)

这种方法也是一个Qt槽与C + +的签名void start()

启动时间表。QTimeLine将进入运行状态,一旦进入事件循环,它会更新其当前的时间,框架和价值定期进行。默认时间间隔为40毫秒(即每秒25次) 。你可以通过调用更改更新时间间隔setUpdateInterval( ) 。

时间轴会从位置0 ,或结束时,如果倒退启动。如果你想恢复已停止的时间表而不需要重新启动,你可以调用resume( )来代替。

See also resume( )updateInterval( )frameChanged()和valueChanged( ) 。

  1. int QTimeLine.startFrame (self)

返回的起始帧,这是对应于时间线(即对于其当前值是0帧)的开始帧。

See also setStartFrame()和setFrameRange( ) 。

  1. State QTimeLine.state (self)

[

返回时间轴的状态。

]($docs-qtimeline.html#State-enum)

See also start( )setPaused()和stop( ) 。

  1. QTimeLine.stop (self)

这种方法也是一个Qt槽与C + +的签名void stop()

停止时间轴,造成QTimeLine to enter NotRunning状态。

See also start( ) 。

  1. QTimeLine.timerEvent (self, QTimerEvent event)

从重新实现QObject.timerEvent( ) 。

  1. QTimeLine.toggleDirection (self)

这种方法也是一个Qt槽与C + +的签名void toggleDirection()

切换时间线的方向。如果方向是前进,它变得落后,副verca 。

See also setDirection( ) 。

  1. int QTimeLine.updateInterval (self)
  1. float QTimeLine.valueForTime (self, int msec)

返回时间轴价值的时间msec。返回的值,取决于曲线的形状而变化,始终为0和1之间。如果msec为0时,默认的实现始终返回0 。

重新实现这个函数提供一个自定义的曲线形状为你的时间表。

See also CurveShapeframeForTime( ) 。


Qt Signal Documentation

  1. void finished ()

这是该信号的默认超载。

这个信号被发射时QTimeLine完成(即达到其时间线的末端)和不循环。

  1. void frameChanged (int)

这是该信号的默认超载。

QTimeLine以规则间隔发出该信号在时Running状态,但只有在当前帧的变化。frame是当前帧号。

See also QTimeLine.setFrameRange()和QTimeLine.updateInterval

  1. void stateChanged (QTimeLine::State)

这是该信号的默认超载。

这个信号被发射时QTimeLine的状态变化。新的状态是newState

  1. void valueChanged (qreal)

这是该信号的默认超载。

QTimeLine以规则间隔发出该信号在时Running状态,但只有当电流值而变化。value是当前值。value是一个介于0.0和1.0之间

See also QTimeLine.setDuration( )QTimeLine.valueForTime()和QTimeLine.updateInterval