PySide6.QtGui.QMovie¶
- class QMovie¶
The
QMovieclass is a convenience class for playing movies withQImageReader. More…Synopsis¶
Properties¶
cacheModeᅟ- The movie’s cache modespeedᅟ- The movie’s speed
Methods¶
def
__init__()def
cacheMode()def
currentImage()def
currentPixmap()def
device()def
fileName()def
format()def
frameCount()def
frameRect()def
isValid()def
jumpToFrame()def
lastError()def
loopCount()def
nextFrameDelay()def
scaledSize()def
setCacheMode()def
setDevice()def
setFileName()def
setFormat()def
setScaledSize()def
speed()def
state()
Slots¶
def
setPaused()def
setSpeed()def
start()def
stop()
Signals¶
def
error()def
finished()def
frameChanged()def
resized()def
started()def
stateChanged()def
updated()
Static functions¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This class is used to show simple animations without sound.
First, create a
QMovieobject by passing either the name of a file or a pointer to a QIODevice containing an animated image format toQMovie‘s constructor. You can callisValid()to check if the image data is valid, before starting the movie. To start the movie, callstart().QMoviewill enterRunningstate, and emitstarted()andstateChanged(). To get the current state of the movie, callstate().To display the movie in your application, you can pass your
QMovieobject to QLabel::setMovie(). Example:label = QLabel() movie = QMovie("animations/fire.gif") label.setMovie(movie) movie.start()
Whenever a new frame is available in the movie,
QMoviewill emitupdated(). If the size of the frame changes,resized()is emitted. You can callcurrentImage()orcurrentPixmap()to get a copy of the current frame. When the movie is done,QMovieemitsfinished(). If any error occurs during playback (i.e, the image file is corrupt),QMoviewill emiterror().You can control the speed of the movie playback by calling
setSpeed(), which takes the percentage of the original speed as an argument. Pause the movie by callingsetPaused(true).QMoviewill then enterPausedstate and emitstateChanged(). If you callsetPaused(false),QMoviewill reenterRunningstate and start the movie again. To stop the movie, callstop().Certain animation formats allow you to set the background color. You can call
setBackgroundColor()to set the color, orbackgroundColor()to retrieve the current background color.currentFrameNumber()returns the sequence number of the current frame. The first frame in the animation has the sequence number 0.frameCount()returns the total number of frames in the animation, if the image format supports this. You can callloopCount()to get the number of times the movie should loop before finishing.nextFrameDelay()returns the number of milliseconds the current frame should be displayed.QMoviecan be instructed to cache frames of an animation by callingsetCacheMode().Call
supportedFormats()for a list of formats thatQMoviesupports.See also
- class MovieState¶
This enum describes the different states of
QMovie.Constant
Description
QMovie.MovieState.NotRunning
The movie is not running. This is
QMovie‘s initial state, and the state it enters afterstop()has been called or the movie is finished.QMovie.MovieState.Paused
The movie is paused, and
QMoviestops emittingupdated()orresized(). This state is entered after calling pause() orsetPaused(true). The current frame number it kept, and the movie will continue with the next frame when unpause() orsetPaused(false) is called.QMovie.MovieState.Running
The movie is running.
- class CacheMode¶
This enum describes the different cache modes of
QMovie.Constant
Description
QMovie.CacheMode.CacheNone
No frames are cached (the default).
QMovie.CacheMode.CacheAll
All frames are cached.
Note
Properties can be used directly when
from __feature__ import true_propertyis used or via accessor functions otherwise.- property cacheModeᅟ: QMovie.CacheMode¶
This property holds the movie’s cache mode.
Caching frames can be useful when the underlying animation format handler that
QMovierelies on to decode the animation data does not support jumping to particular frames in the animation, or even “rewinding” the animation to the beginning (for looping). Furthermore, if the image data comes from a sequential device, it is not possible for the underlying animation handler to seek back to frames whose data has already been read (making looping altogether impossible).To aid in such situations, a
QMovieobject can be instructed to cache the frames, at the added memory cost of keeping the frames in memory for the lifetime of the object.By default, this property is set to
CacheNone.See also
- Access functions:
- property speedᅟ: int¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This property holds the movie’s speed.
The speed is measured in percentage of the original movie speed. The default speed is 100%. Example:
movie = QMovie("racecar.gif") movie.setSpeed(200) # 2x speed
- Access functions:
Constructs a
QMovieobject, passing theparentobject to QObject’s constructor.See also
- __init__(device[, format=QByteArray()[, parent=None]])
- Parameters:
device –
QIODeviceformat –
QByteArrayparent –
QObject
Constructs a
QMovieobject.QMoviewill use read image data fromdevice, which it assumes is open and readable. Ifformatis not empty,QMoviewill use the image formatformatfor decoding the image data. Otherwise,QMoviewill attempt to guess the format.The
parentobject is passed to QObject’s constructor.- __init__(fileName[, format=QByteArray()[, parent=None]])
- Parameters:
fileName – str
format –
QByteArrayparent –
QObject
Constructs a
QMovieobject.QMoviewill use read image data fromfileName. Ifformatis not empty,QMoviewill use the image formatformatfor decoding the image data. Otherwise,QMoviewill attempt to guess the format.The
parentobject is passed to QObject’s constructor.Returns the background color of the movie. If no background color has been assigned, an invalid
QColoris returned.See also
- cacheMode()¶
- Return type:
See also
Getter of property
cacheModeᅟ.- currentFrameNumber()¶
- Return type:
int
Returns the sequence number of the current frame. The number of the first frame in the movie is 0.
Returns the current frame as a
QImage.See also
Returns the current frame as a
QPixmap.See also
Returns the device
QMoviereads image data from. If no device has currently been assigned,Noneis returned.See also
- error(error)¶
- Parameters:
error –
ImageReaderError
This signal is emitted by
QMoviewhen the errorerroroccurred during playback.QMoviewill stop the movie, and enterNotRunningstate.See also
- fileName()¶
- Return type:
str
Returns the name of the file that
QMoviereads image data from. If no file name has been assigned, or if the assigned device is not a file, an empty QString is returned.See also
- finished()¶
This signal is emitted when the movie has finished.
See also
- format()¶
- Return type:
Returns the format that
QMovieuses when decoding image data. If no format has been assigned, an empty QByteArray() is returned.See also
- frameChanged(frameNumber)¶
- Parameters:
frameNumber – int
This signal is emitted when the frame number has changed to
frameNumber. You can callcurrentImage()orcurrentPixmap()to get a copy of the frame.- frameCount()¶
- Return type:
int
Returns the number of frames in the movie.
Certain animation formats do not support this feature, in which case 0 is returned.
Returns the rect of the last frame. If no frame has yet been updated, an invalid QRect is returned.
See also
- isValid()¶
- Return type:
bool
Returns
trueif the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returnsfalse.For information about why the movie is not valid, see
lastError().- jumpToFrame(frameNumber)¶
- Parameters:
frameNumber – int
- Return type:
bool
Jumps to frame number
frameNumber. Returnstrueon success; otherwise returnsfalse.- jumpToNextFrame()¶
- Return type:
bool
Jumps to the next frame. Returns
trueon success; otherwise returnsfalse.- lastError()¶
- Return type:
Returns the most recent error that occurred while attempting to read image data.
See also
- lastErrorString()¶
- Return type:
str
Returns a human-readable representation of the most recent error that occurred while attempting to read image data.
See also
- loopCount()¶
- Return type:
int
Returns the number of times the movie will loop before it finishes. If the movie will only play once (no looping), loopCount returns 0. If the movie loops forever, loopCount returns -1.
Note that, if the image data comes from a sequential device (e.g. a socket),
QMoviecan only loop the movie if thecacheModeis set toCacheAll.- nextFrameDelay()¶
- Return type:
int
Returns the number of milliseconds
QMoviewill wait before updating the next frame in the animation.This signal is emitted when the current frame has been resized to
size. This effect is sometimes used in animations as an alternative to replacing the frame. You can callcurrentImage()orcurrentPixmap()to get a copy of the updated frame.Returns the scaled size of frames.
See also
For image formats that support it, this function sets the background color to
color.See also
Setter of property
cacheModeᅟ.Sets the current device to
device.QMoviewill read image data from this device when the movie is running.See also
- setFileName(fileName)¶
- Parameters:
fileName – str
Sets the name of the file that
QMoviereads image data from, tofileName.See also
- setFormat(format)¶
- Parameters:
format –
QByteArray
Sets the format that
QMoviewill use when decoding image data, toformat. By default,QMoviewill attempt to guess the format of the image data.You can call
supportedFormats()for the full list of formatsQMoviesupports.See also
- setPaused(paused)¶
- Parameters:
paused – bool
If
pausedis true,QMoviewill enterPausedstate and emitstateChanged(Paused); otherwise it will enterRunningstate and emitstateChanged(Running).See also
Sets the scaled frame size to
size.See also
Setter of property
speedᅟ.- speed()¶
- Return type:
int
See also
Getter of property
speedᅟ.- start()¶
Starts the movie.
QMoviewill enterRunningstate, and start emittingupdated()andresized()as the movie progresses.If
QMovieis in thePausedstate, this function is equivalent to callingsetPaused(false). IfQMovieis already in theRunningstate, this function does nothing.See also
- started()¶
This signal is emitted after
start()has been called, andQMoviehas enteredRunningstate.- state()¶
- Return type:
Returns the current state of
QMovie.See also
- stateChanged(state)¶
- Parameters:
state –
MovieState
This signal is emitted every time the state of the movie changes. The new state is specified by
state.See also
- stop()¶
Stops the movie.
QMovieentersNotRunningstate, and stops emittingupdated()andresized(). Ifstart()is called again, the movie will restart from the beginning.If
QMovieis already in theNotRunningstate, this function does nothing.See also
- static supportedFormats()¶
- Return type:
.list of QByteArray
Returns the list of image formats supported by
QMovie.See also
This signal is emitted when the rect
rectin the current frame has been updated. You can callcurrentImage()orcurrentPixmap()to get a copy of the updated frame.