def
currentFrame
()
def
currentTime
()
def
currentValue
()
def
curveShape
()
def
direction
()
def
duration
()
def
easingCurve
()
def
endFrame
()
def
frameForTime
(msec)
def
loopCount
()
def
setCurveShape
(shape)
def
setDirection
(direction)
def
setDuration
(duration)
def
setEasingCurve
(curve)
def
setEndFrame
(frame)
def
setFrameRange
(startFrame, endFrame)
def
setLoopCount
(count)
def
setStartFrame
(frame)
def
setUpdateInterval
(interval)
def
startFrame
()
def
state
()
def
updateInterval
()
def
valueForTime
(msec)
def
resume
()
def
setCurrentTime
(msec)
def
setPaused
(paused)
def
start
()
def
stop
()
def
toggleDirection
()
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
QTimeLine‘s constructor. The timeline’s duration describes for how long the animation will run. Then you set a suitable frame range by callingsetFrameRange(). Finally connect theframeChanged()signal to a suitable slot in the widget you wish to animate (for example,setValue()inQProgressBar). When you proceed to callingstart(),QTimeLinewill enter Running state, and start emittingframeChanged()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 callingsetUpdateInterval(). When done,QTimeLine进入NotRunningstate, and emitsfinished().范例:
... 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) ...By default the timeline runs once, from the beginning and towards the end, upon which you must call
start()again to restart from the beginning. To make the timeline loop, you can callsetLoopCount(), passing the number of times the timeline should run before finishing. The direction can also be changed, causing the timeline to run backward, by callingsetDirection(). You can also pause and unpause the timeline while it’s running by callingsetPaused(). For interactive control, thesetCurrentTime()function is provided, which sets the time position of the time line directly. Although most useful inNotRunningstate, (e.g., connected to avalueChanged()signal in aQSlider,) this function can be called at any time.The frame interface is useful for standard widgets, but
QTimeLinecan be used to control any type of animation. The heart ofQTimeLinelies in thevalueForTime()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,QTimeLinegenerates values between 0 and 1 by callingvalueForTime()and emittingvalueChanged(). By default,valueForTime()applies an interpolation algorithm to generate these value. You can choose from a set of predefined timeline algorithms by callingsetCurveShape().Note that by default,
QTimeLineuses the EaseInOut curve shape, which provides a value that grows slowly, then grows steadily, and finally grows slowly. For a custom timeline, you can reimplementvalueForTime(), in which caseQTimeLine‘scurveShapeproperty is ignored.
QTimeLine
(
[
duration=1000
[
,
parent=None
]
]
)
¶
- param parent
- param duration
int
Constructs a timeline with a duration of
duration
毫秒。
parent
会被传递给
QObject
‘s constructor. The default duration is 1000 milliseconds.
PySide2.QtCore.QTimeLine.
State
¶
This enum describes the state of the timeline.
|
常量 |
描述 |
|---|---|
|
QTimeLine.NotRunning |
The timeline is not running. This is the initial state of
|
|
QTimeLine.Paused |
The timeline is paused (i.e., temporarily suspended). Calling
|
|
QTimeLine.Running |
The timeline is running. While control is in the event loop,
|
另请参阅
state()
stateChanged()
PySide2.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). |
另请参阅
PySide2.QtCore.QTimeLine.
CurveShape
¶
This enum describes the default shape of
QTimeLine
‘s value curve. The default, shape is . 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. |
另请参阅
PySide2.QtCore.QTimeLine.
currentFrame
(
)
¶
int
Returns the frame corresponding to the current time.
PySide2.QtCore.QTimeLine.
currentTime
(
)
¶
int
另请参阅
PySide2.QtCore.QTimeLine.
currentValue
(
)
¶
qreal
Returns the value corresponding to the current time.
PySide2.QtCore.QTimeLine.
curveShape
(
)
¶
另请参阅
PySide2.QtCore.QTimeLine.
direction
(
)
¶
另请参阅
PySide2.QtCore.QTimeLine.
duration
(
)
¶
int
另请参阅
PySide2.QtCore.QTimeLine.
easingCurve
(
)
¶
另请参阅
PySide2.QtCore.QTimeLine.
endFrame
(
)
¶
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).
PySide2.QtCore.QTimeLine.
frameForTime
(
msec
)
¶
msec
–
int
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
valueForTime()
.
PySide2.QtCore.QTimeLine.
loopCount
(
)
¶
int
另请参阅
PySide2.QtCore.QTimeLine.
resume
(
)
¶
Resumes the timeline from the current time.
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
start()
, this function does not restart the timeline before it resumes.
另请参阅
start()
updateInterval()
frameChanged()
valueChanged()
PySide2.QtCore.QTimeLine.
setCurrentTime
(
msec
)
¶
msec
–
int
另请参阅
PySide2.QtCore.QTimeLine.
setCurveShape
(
shape
)
¶
shape
–
CurveShape
另请参阅
PySide2.QtCore.QTimeLine.
setDuration
(
duration
)
¶
duration
–
int
另请参阅
PySide2.QtCore.QTimeLine.
setEasingCurve
(
curve
)
¶
curve
–
QEasingCurve
另请参阅
PySide2.QtCore.QTimeLine.
setEndFrame
(
frame
)
¶
frame
–
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
.
PySide2.QtCore.QTimeLine.
setFrameRange
(
startFrame
,
endFrame
)
¶
startFrame
–
int
endFrame
–
int
Sets the timeline’s frame counter to start at
startFrame
, and end and
endFrame
. For each time value,
QTimeLine
will find the corresponding frame when you call
currentFrame()
or
frameForTime()
by interpolating, using the return value of
valueForTime()
.
When in Running state,
QTimeLine
also emits the
frameChanged()
signal when the frame changes.
PySide2.QtCore.QTimeLine.
setLoopCount
(
count
)
¶
count
–
int
另请参阅
PySide2.QtCore.QTimeLine.
setPaused
(
paused
)
¶
paused
–
bool
若
paused
is true, the timeline is paused, causing
QTimeLine
to enter Paused state. No updates will be signaled until either
start()
or (false) is called. If
paused
is false, the timeline is resumed and continues where it left.
PySide2.QtCore.QTimeLine.
setStartFrame
(
frame
)
¶
frame
–
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
.
PySide2.QtCore.QTimeLine.
setUpdateInterval
(
interval
)
¶
interval
–
int
另请参阅
PySide2.QtCore.QTimeLine.
start
(
)
¶
Starts the timeline.
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
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
resume()
代替。
另请参阅
resume()
updateInterval()
frameChanged()
valueChanged()
PySide2.QtCore.QTimeLine.
startFrame
(
)
¶
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).
PySide2.QtCore.QTimeLine.
state
(
)
¶
Returns the state of the timeline.
另请参阅
PySide2.QtCore.QTimeLine.
stop
(
)
¶
Stops the timeline, causing
QTimeLine
to enter
NotRunning
状态。
另请参阅
PySide2.QtCore.QTimeLine.
toggleDirection
(
)
¶
Toggles the direction of the timeline. If the direction was Forward, it becomes Backward, and vice verca.
另请参阅
PySide2.QtCore.QTimeLine.
updateInterval
(
)
¶
int
另请参阅
PySide2.QtCore.QTimeLine.
valueForTime
(
msec
)
¶
msec
–
int
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.
另请参阅
CurveShape
frameForTime()