• PySide 模块
  • PySide.QtCore
  • 内容表

    上一话题

    QObject

    下一话题

    QAbstractAnimation

    QTimeLine

    概要

    函数

    虚函数

    信号

    详细描述

    PySide.QtCore.QTimeLine class provides a timeline for controlling animations.

    It's most commonly used to animate a GUI control by calling a slot periodically. You can construct a timeline by passing its duration in milliseconds to PySide.QtCore.QTimeLine ‘s constructor. The timeline's duration describes for how long the animation will run. Then you set a suitable frame range by calling PySide.QtCore.QTimeLine.setFrameRange() . Finally connect the PySide.QtCore.QTimeLine.frameChanged() signal to a suitable slot in the widget you wish to animate (e.g., setValue() in PySide.QtGui.QProgressBar ). When you proceed to calling PySide.QtCore.QTimeLine.start() , PySide.QtCore.QTimeLine will enter Running state, and start emitting PySide.QtCore.QTimeLine.frameChanged() at regular intervals, causing your widget's connected property's value to grow from the lower end to the upper and of your frame range, at a steady rate. You can specify the update interval by calling PySide.QtCore.QTimeLine.setUpdateInterval() . When done, PySide.QtCore.QTimeLine 进入 NotRunning state, and emits PySide.QtCore.QTimeLine.finished() .

    范例:

    ...
    progressBar = QProgressBar(self)
    progressBar.setRange(0, 100)
    # Construct a 1-second timeline with a frame range of 0 - 100
    timeLine = QTimeLine(1000, self)
    timeLine.setFrameRange(0, 100)
    timeLine.frameChanged[int].connect(progressBar.setValue)
    # Clicking the push button will start the progress bar animation
    pushButton = QPushButton(QObject.tr("Start animation"), self)
    pushButton.clicked.connect(timeLine.start)
    ...
    										

    还可以使用 PySide.QtCore.QTimeLine 采用 Graphics View framework for animations. The PySide.QtGui.QGraphicsItemAnimation class implements animation of QGraphicsItems with a timeline.

    By default the timeline runs once, from the beginning and towards the end, upon which you must call PySide.QtCore.QTimeLine.start() again to restart from the beginning. To make the timeline loop, you can call PySide.QtCore.QTimeLine.setLoopCount() , passing the number of times the timeline should run before finishing. The direction can also be changed, causing the timeline to run backward, by calling PySide.QtCore.QTimeLine.setDirection() . You can also pause and unpause the timeline while it's running by calling PySide.QtCore.QTimeLine.setPaused() . For interactive control, the PySide.QtCore.QTimeLine.setCurrentTime() function is provided, which sets the time position of the time line directly. Although most useful in NotRunning state, (e.g., connected to a PySide.QtCore.QTimeLine.valueChanged() signal in a PySide.QtGui.QSlider ,) this function can be called at any time.

    The frame interface is useful for standard widgets, but PySide.QtCore.QTimeLine can be used to control any type of animation. The heart of PySide.QtCore.QTimeLine lies in the PySide.QtCore.QTimeLine.valueForTime() function, which generates a value between 0 and 1 for a given time. This value is typically used to describe the steps of an animation, where 0 is the first step of an animation, and 1 is the last step. When running, PySide.QtCore.QTimeLine generates values between 0 and 1 by calling PySide.QtCore.QTimeLine.valueForTime() and emitting PySide.QtCore.QTimeLine.valueChanged() . By default, PySide.QtCore.QTimeLine.valueForTime() applies an interpolation algorithm to generate these value. You can choose from a set of predefined timeline algorithms by calling PySide.QtCore.QTimeLine.setCurveShape() .

    Note that by default, PySide.QtCore.QTimeLine uses the EaseInOut curve shape, which provides a value that grows slowly, then grows steadily, and finally grows slowly. For a custom timeline, you can reimplement PySide.QtCore.QTimeLine.valueForTime() , in which case PySide.QtCore.QTimeLine ‘s PySide.QtCore.QTimeLine.curveShape() property is ignored.

    class PySide.QtCore. QTimeLine ( [ duration=1000 [ , parent=None ] ] )
    参数:

    Constructs a timeline with a duration of duration 毫秒。 parent 会被传递给 PySide.QtCore.QObject ‘s constructor. The default duration is 1000 milliseconds.

    PySide.QtCore.QTimeLine. Direction

    This enum describes the direction of the timeline when in 运行 状态。

    常量 描述
    QTimeLine.Forward The current time of the timeline increases with time (i.e., moves from 0 and towards the end / duration).
    QTimeLine.Backward The current time of the timeline decreases with time (i.e., moves from the end / duration and towards 0).
    PySide.QtCore.QTimeLine. CurveShape

    This enum describes the default shape of PySide.QtCore.QTimeLine ‘s value curve. The default, shape is EaseInOutCurve . The curve defines the relation between the value and the timeline.

    常量 描述
    QTimeLine.EaseInCurve The value starts growing slowly, then increases in speed.
    QTimeLine.EaseOutCurve The value starts growing steadily, then ends slowly.
    QTimeLine.EaseInOutCurve The value starts growing slowly, then runs steadily, then grows slowly again.
    QTimeLine.LinearCurve The value grows linearly (e.g., if the duration is 1000 ms, the value at time 500 ms is 0.5).
    QTimeLine.SineCurve The value grows sinusoidally.
    QTimeLine.CosineCurve The value grows cosinusoidally.
    PySide.QtCore.QTimeLine. State

    This enum describes the state of the timeline.

    常量 描述
    QTimeLine.NotRunning The timeline is not running. This is the initial state of PySide.QtCore.QTimeLine , and the state PySide.QtCore.QTimeLine reenters when finished. The current time, frame and value remain unchanged until either PySide.QtCore.QTimeLine.setCurrentTime() is called, or the timeline is started by calling PySide.QtCore.QTimeLine.start() .
    QTimeLine.Paused The timeline is paused (i.e., temporarily suspended). Calling setPaused(false) will resume timeline activity.
    QTimeLine.Running The timeline is running. While control is in the event loop, PySide.QtCore.QTimeLine will update its current time at regular intervals, emitting PySide.QtCore.QTimeLine.valueChanged() and PySide.QtCore.QTimeLine.frameChanged() when appropriate.
    PySide.QtCore.QTimeLine. currentFrame ( )
    返回类型: PySide.QtCore.int

    Returns the frame corresponding to the current time.

    PySide.QtCore.QTimeLine. currentTime ( )
    返回类型: PySide.QtCore.int

    This property holds the current time of the time line..

    PySide.QtCore.QTimeLine is in Running state, this value is updated continuously as a function of the duration and direction of the timeline. Otherwise, it is value that was current when PySide.QtCore.QTimeLine.stop() was called last, or the value set by PySide.QtCore.QTimeLine.setCurrentTime() .

    默认情况下,此特性包含 0 值。

    PySide.QtCore.QTimeLine. currentValue ( )
    返回类型: PySide.QtCore.qreal

    Returns the value corresponding to the current time.

    PySide.QtCore.QTimeLine. curveShape ( )
    返回类型: PySide.QtCore.QTimeLine.CurveShape

    This property holds the shape of the timeline curve..

    The curve shape describes the relation between the time and value for the base implementation of PySide.QtCore.QTimeLine.valueForTime() .

    If you have reimplemented PySide.QtCore.QTimeLine.valueForTime() , this value is ignored.

    默认情况下,此特性被设为 EaseInOutCurve .

    PySide.QtCore.QTimeLine. direction ( )
    返回类型: PySide.QtCore.QTimeLine.Direction

    This property holds the direction of the timeline when PySide.QtCore.QTimeLine 是在 运行 state..

    This direction indicates whether the time moves from 0 towards the timeline duration, or from the value of the duration and towards 0 after PySide.QtCore.QTimeLine.start() has been called.

    默认情况下,此特性被设为 Forward .

    PySide.QtCore.QTimeLine. duration ( )
    返回类型: PySide.QtCore.int

    This property holds the total duration of the timeline in milliseconds..

    By default, this value is 1000 (i.e., 1 second), but you can change this by either passing a duration to PySide.QtCore.QTimeLine ‘s constructor, or by calling PySide.QtCore.QTimeLine.setDuration() . The duration must be larger than 0.

    注意

    Changing the duration does not cause the current time to be reset to zero or the new duration. You also need to call PySide.QtCore.QTimeLine.setCurrentTime() with the desired value.

    PySide.QtCore.QTimeLine. easingCurve ( )
    返回类型: PySide.QtCore.QEasingCurve

    Specifies the easing curve that the timeline will use. If both easing curve and PySide.QtCore.QTimeLine.curveShape() are set, the last set property will override the previous one. (If PySide.QtCore.QTimeLine.valueForTime() is reimplemented it will override both)

    PySide.QtCore.QTimeLine. endFrame ( )
    返回类型: PySide.QtCore.int

    Returns the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1).

    PySide.QtCore.QTimeLine. finished ( )
    PySide.QtCore.QTimeLine. frameChanged ( arg__1 )
    参数: arg__1 PySide.QtCore.int
    PySide.QtCore.QTimeLine. frameForTime ( msec )
    参数: msec PySide.QtCore.int
    返回类型: PySide.QtCore.int

    Returns the frame corresponding to the time msec . This value is calculated using a linear interpolation of the start and end frame, based on the value returned by PySide.QtCore.QTimeLine.valueForTime() .

    PySide.QtCore.QTimeLine. loopCount ( )
    返回类型: PySide.QtCore.int

    This property holds the number of times the timeline should loop before it's finished..

    A loop count of of 0 means that the timeline will loop forever.

    By default, this property contains a value of 1.

    PySide.QtCore.QTimeLine. resume ( )

    Resumes the timeline from the current time. PySide.QtCore.QTimeLine will reenter Running state, and once it enters the event loop, it will update its current time, frame and value at regular intervals.

    In contrast to PySide.QtCore.QTimeLine.start() , this function does not restart the timeline before it resumes.

    PySide.QtCore.QTimeLine. setCurrentTime ( msec )
    参数: msec PySide.QtCore.int

    This property holds the current time of the time line..

    PySide.QtCore.QTimeLine is in Running state, this value is updated continuously as a function of the duration and direction of the timeline. Otherwise, it is value that was current when PySide.QtCore.QTimeLine.stop() was called last, or the value set by PySide.QtCore.QTimeLine.setCurrentTime() .

    默认情况下,此特性包含 0 值。

    PySide.QtCore.QTimeLine. setCurveShape ( shape )
    参数: shape PySide.QtCore.QTimeLine.CurveShape

    This property holds the shape of the timeline curve..

    The curve shape describes the relation between the time and value for the base implementation of PySide.QtCore.QTimeLine.valueForTime() .

    If you have reimplemented PySide.QtCore.QTimeLine.valueForTime() , this value is ignored.

    默认情况下,此特性被设为 EaseInOutCurve .

    PySide.QtCore.QTimeLine. setDirection ( direction )
    参数: direction PySide.QtCore.QTimeLine.Direction

    This property holds the direction of the timeline when PySide.QtCore.QTimeLine 是在 运行 state..

    This direction indicates whether the time moves from 0 towards the timeline duration, or from the value of the duration and towards 0 after PySide.QtCore.QTimeLine.start() has been called.

    默认情况下,此特性被设为 Forward .

    PySide.QtCore.QTimeLine. setDuration ( duration )
    参数: duration PySide.QtCore.int

    This property holds the total duration of the timeline in milliseconds..

    By default, this value is 1000 (i.e., 1 second), but you can change this by either passing a duration to PySide.QtCore.QTimeLine ‘s constructor, or by calling PySide.QtCore.QTimeLine.setDuration() . The duration must be larger than 0.

    注意

    Changing the duration does not cause the current time to be reset to zero or the new duration. You also need to call PySide.QtCore.QTimeLine.setCurrentTime() with the desired value.

    PySide.QtCore.QTimeLine. setEasingCurve ( curve )
    参数: curve PySide.QtCore.QEasingCurve

    Specifies the easing curve that the timeline will use. If both easing curve and PySide.QtCore.QTimeLine.curveShape() are set, the last set property will override the previous one. (If PySide.QtCore.QTimeLine.valueForTime() is reimplemented it will override both)

    PySide.QtCore.QTimeLine. setEndFrame ( frame )
    参数: frame PySide.QtCore.int

    Sets the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1), to frame .

    PySide.QtCore.QTimeLine. setFrameRange ( startFrame , endFrame )
    参数:
    • startFrame PySide.QtCore.int
    • endFrame PySide.QtCore.int

    Sets the timeline's frame counter to start at startFrame , and end and endFrame . For each time value, PySide.QtCore.QTimeLine will find the corresponding frame when you call PySide.QtCore.QTimeLine.currentFrame() or PySide.QtCore.QTimeLine.frameForTime() by interpolating, using the return value of PySide.QtCore.QTimeLine.valueForTime() .

    When in Running state, PySide.QtCore.QTimeLine also emits the PySide.QtCore.QTimeLine.frameChanged() signal when the frame changes.

    PySide.QtCore.QTimeLine. setLoopCount ( count )
    参数: count PySide.QtCore.int

    This property holds the number of times the timeline should loop before it's finished..

    A loop count of of 0 means that the timeline will loop forever.

    By default, this property contains a value of 1.

    PySide.QtCore.QTimeLine. setPaused ( paused )
    参数: paused PySide.QtCore.bool

    paused is true, the timeline is paused, causing PySide.QtCore.QTimeLine to enter Paused state. No updates will be signaled until either PySide.QtCore.QTimeLine.start() or setPaused(false) is called. If paused is false, the timeline is resumed and continues where it left.

    PySide.QtCore.QTimeLine. setStartFrame ( frame )
    参数: frame PySide.QtCore.int

    Sets the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0), to frame .

    PySide.QtCore.QTimeLine. setUpdateInterval ( interval )
    参数: interval PySide.QtCore.int

    This property holds the time in milliseconds between each time PySide.QtCore.QTimeLine updates its current time..

    When updating the current time, PySide.QtCore.QTimeLine 将发射 PySide.QtCore.QTimeLine.valueChanged() if the current value changed, and PySide.QtCore.QTimeLine.frameChanged() if the frame changed.

    By default, the interval is 40 ms, which corresponds to a rate of 25 updates per second.

    PySide.QtCore.QTimeLine. start ( )

    Starts the timeline. PySide.QtCore.QTimeLine will enter Running state, and once it enters the event loop, it will update its current time, frame and value at regular intervals. The default interval is 40 ms (i.e., 25 times per second). You can change the update interval by calling PySide.QtCore.QTimeLine.setUpdateInterval() .

    The timeline will start from position 0, or the end if going backward. If you want to resume a stopped timeline without restarting, you can call PySide.QtCore.QTimeLine.resume() 代替。

    PySide.QtCore.QTimeLine. startFrame ( )
    返回类型: PySide.QtCore.int

    Returns the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0).

    PySide.QtCore.QTimeLine. state ( )
    返回类型: PySide.QtCore.QTimeLine.State

    Returns the state of the timeline.

    PySide.QtCore.QTimeLine. stateChanged ( newState )
    参数: newState PySide.QtCore.QTimeLine.State
    PySide.QtCore.QTimeLine. stop ( )

    Stops the timeline, causing PySide.QtCore.QTimeLine to enter NotRunning 状态。

    PySide.QtCore.QTimeLine. toggleDirection ( )

    Toggles the direction of the timeline. If the direction was Forward, it becomes Backward, and vice verca.

    PySide.QtCore.QTimeLine. updateInterval ( )
    返回类型: PySide.QtCore.int

    This property holds the time in milliseconds between each time PySide.QtCore.QTimeLine updates its current time..

    When updating the current time, PySide.QtCore.QTimeLine 将发射 PySide.QtCore.QTimeLine.valueChanged() if the current value changed, and PySide.QtCore.QTimeLine.frameChanged() if the frame changed.

    By default, the interval is 40 ms, which corresponds to a rate of 25 updates per second.

    PySide.QtCore.QTimeLine. valueChanged ( x )
    参数: x PySide.QtCore.qreal
    PySide.QtCore.QTimeLine. valueForTime ( msec )
    参数: msec PySide.QtCore.int
    返回类型: PySide.QtCore.qreal

    Returns the timeline value for the time msec . The returned value, which varies depending on the curve shape, is always between 0 and 1. If msec is 0, the default implementation always returns 0.

    Reimplement this function to provide a custom curve shape for your timeline.

    另请参阅

    QTimeLine.CurveShape PySide.QtCore.QTimeLine.frameForTime()