
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQMovie class is a convenience class for playing movies withQImageReader.More...
| Header: | #include <QMovie> |
| Inherits: | QObject |
| enum | CacheMode { CacheNone, CacheAll } |
| enum | MovieState { NotRunning, Paused, Running } |
| QMovie(QObject * parent = 0) | |
| QMovie(QIODevice * device, const QByteArray & format = QByteArray(), QObject * parent = 0) | |
| QMovie(const QString & fileName, const QByteArray & format = QByteArray(), QObject * parent = 0) | |
| ~QMovie() | |
| QColor | backgroundColor() const |
| CacheMode | cacheMode() const |
| int | currentFrameNumber() const |
| QImage | currentImage() const |
| QPixmap | currentPixmap() const |
| QIODevice * | device() const |
| QString | fileName() const |
| QByteArray | format() const |
| int | frameCount() const |
| QRect | frameRect() const |
| bool | isValid() const |
| bool | jumpToFrame(int frameNumber) |
| int | loopCount() const |
| int | nextFrameDelay() const |
| QSize | scaledSize() |
| void | setBackgroundColor(const QColor & color) |
| void | setCacheMode(CacheMode mode) |
| void | setDevice(QIODevice * device) |
| void | setFileName(const QString & fileName) |
| void | setFormat(const QByteArray & format) |
| void | setScaledSize(const QSize & size) |
| int | speed() const |
| MovieState | state() const |
| bool | jumpToNextFrame() |
| void | setPaused(bool paused) |
| void | setSpeed(int percentSpeed) |
| void | start() |
| void | stop() |
| void | error(QImageReader::ImageReaderError error) |
| void | finished() |
| void | frameChanged(int frameNumber) |
| void | resized(const QSize & size) |
| void | started() |
| void | stateChanged(QMovie::MovieState state) |
| void | updated(const QRect & rect) |
| QList<QByteArray> | supportedFormats() |
TheQMovie class is a convenience class for playing movies withQImageReader.
This class is used to show simple animations without sound. If you want to display video and media content, use thePhonon multimedia framework instead.
First, create aQMovie object by passing either the name of a file or a pointer to aQIODevice 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().QMovie will enterRunning state, and emitstarted() andstateChanged(). To get the current state of the movie, callstate().
To display the movie in your application, you can pass yourQMovie object toQLabel::setMovie(). Example:
Whenever a new frame is available in the movie,QMovie will 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,QMovie emitsfinished(). If any error occurs during playback (i.e, the image file is corrupt),QMovie will emiterror().
You can control the speed of the movie playback by callingsetSpeed(), which takes the percentage of the original speed as an argument. Pause the movie by callingsetPaused(true).QMovie will then enterPaused state and emitstateChanged(). If you callsetPaused(false),QMovie will reenterRunning state and start the movie again. To stop the movie, callstop().
Certain animation formats allow you to set the background color. You can callsetBackgroundColor() 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.
QMovie can be instructed to cache frames of an animation by callingsetCacheMode().
CallsupportedFormats() for a list of formats thatQMovie supports.
See alsoQLabel,QImageReader, andMovie Example.
This enum describes the different cache modes ofQMovie.
| Constant | Value | Description |
|---|---|---|
QMovie::CacheNone | 0 | No frames are cached (the default). |
QMovie::CacheAll | 1 | All frames are cached. |
This enum describes the different states ofQMovie.
| Constant | Value | Description |
|---|---|---|
QMovie::NotRunning | 0 | The movie is not running. This isQMovie's initial state, and the state it enters afterstop() has been called or the movie is finished. |
QMovie::Paused | 1 | The movie is paused, andQMovie stops emittingupdated() orresized(). This state is entered after callingpause() orsetPaused(true). The current frame number it kept, and the movie will continue with the next frame whenunpause() orsetPaused(false) is called. |
QMovie::Running | 2 | The movie is running. |
This property holds the movie's cache mode.
Caching frames can be useful when the underlying animation format handler thatQMovie relies 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, aQMovie object 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 toCacheNone.
Access functions:
| CacheMode | cacheMode() const |
| void | setCacheMode(CacheMode mode) |
See alsoQMovie::CacheMode.
This property holds the movie's speed.
The speed is measured in percentage of the original movie speed. The default speed is 100%. Example:
QMovie movie("racecar.gif");movie.setSpeed(200);// 2x speed
Access functions:
| int | speed() const |
| void | setSpeed(int percentSpeed) |
Constructs aQMovie object, passing theparent object toQObject's constructor.
See alsosetFileName(),setDevice(), andsetFormat().
Constructs aQMovie object.QMovie will use read image data fromdevice, which it assumes is open and readable. Ifformat is not empty,QMovie will use the image formatformat for decoding the image data. Otherwise,QMovie will attempt to guess the format.
Theparent object is passed toQObject's constructor.
Constructs aQMovie object.QMovie will use read image data fromfileName. Ifformat is not empty,QMovie will use the image formatformat for decoding the image data. Otherwise,QMovie will attempt to guess the format.
Theparent object is passed toQObject's constructor.
Destructs theQMovie object.
Returns the background color of the movie. If no background color has been assigned, an invalidQColor is returned.
See alsosetBackgroundColor().
Returns the sequence number of the current frame. The number of the first frame in the movie is 0.
Returns the current frame as aQImage.
See alsocurrentPixmap() andupdated().
Returns the current frame as aQPixmap.
See alsocurrentImage() andupdated().
Returns the deviceQMovie reads image data from. If no device has currently been assigned, 0 is returned.
See alsosetDevice() andfileName().
[signal]void QMovie::error(QImageReader::ImageReaderError error)This signal is emitted byQMovie when the errorerror occurred during playback.QMovie will stop the movie, and enterQMovie::NotRunning state.
Returns the name of the file thatQMovie reads image data from. If no file name has been assigned, or if the assigned device is not a file, an emptyQString is returned.
See alsosetFileName() anddevice().
[signal]void QMovie::finished()This signal is emitted when the movie has finished.
Note:Signalfinished is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:
See alsoQMovie::stop().
Returns the format thatQMovie uses when decoding image data. If no format has been assigned, an empty QByteArray() is returned.
See alsosetFormat().
[signal]void QMovie::frameChanged(int frameNumber)This signal is emitted when the frame number has changed toframeNumber. You can callcurrentImage() orcurrentPixmap() to get a copy of the frame.
This function was introduced in Qt 4.1.
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 invalidQRect is returned.
See alsocurrentImage() andcurrentPixmap().
Returns true if the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returns false.
Jumps to frame numberframeNumber. Returns true on success; otherwise returns false.
[slot]bool QMovie::jumpToNextFrame()Jumps to the next frame. Returns true on success; otherwise returns false.
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),QMovie can only loop the movie if thecacheMode is set toQMovie::CacheAll.
Returns the number of millisecondsQMovie will wait before updating the next frame in the animation.
[signal]void QMovie::resized(constQSize & size)This signal is emitted when the current frame has been resized tosize. 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.
This function was introduced in Qt 4.1.
See alsosetScaledSize() andQImageReader::scaledSize().
For image formats that support it, this function sets the background color tocolor.
See alsobackgroundColor().
Sets the current device todevice.QMovie will read image data from this device when the movie is running.
See alsodevice() andsetFormat().
Sets the name of the file thatQMovie reads image data from, tofileName.
See alsofileName(),setDevice(), andsetFormat().
Sets the format thatQMovie will use when decoding image data, toformat. By default,QMovie will attempt to guess the format of the image data.
You can callsupportedFormats() for the full list of formatsQMovie supports.
See alsoformat() andQImageReader::supportedImageFormats().
[slot]void QMovie::setPaused(bool paused)Ifpaused is true,QMovie will enterPaused state and emitstateChanged(Paused); otherwise it will enterRunning state and emitstateChanged(Running).
Sets the scaled frame size tosize.
This function was introduced in Qt 4.1.
See alsoscaledSize() andQImageReader::setScaledSize().
[slot]void QMovie::start()Starts the movie.QMovie will enterRunning state, and start emittingupdated() andresized() as the movie progresses.
IfQMovie is in thePaused state, this function is equivalent to callingsetPaused(false). IfQMovie is already in theRunning state, this function does nothing.
See alsostop() andsetPaused().
[signal]void QMovie::started()This signal is emitted afterQMovie::start() has been called, andQMovie has enteredQMovie::Running state.
Returns the current state ofQMovie.
See alsoMovieState andstateChanged().
[signal]void QMovie::stateChanged(QMovie::MovieState state)This signal is emitted every time the state of the movie changes. The new state is specified bystate.
See alsoQMovie::state().
[slot]void QMovie::stop()Stops the movie.QMovie entersNotRunning state, and stops emittingupdated() andresized(). Ifstart() is called again, the movie will restart from the beginning.
IfQMovie is already in theNotRunning state, this function does nothing.
See alsostart() andsetPaused().
[static]QList<QByteArray> QMovie::supportedFormats()Returns the list of image formats supported byQMovie.
This function was introduced in Qt 4.1.
See alsoQImageReader::supportedImageFormats().
[signal]void QMovie::updated(constQRect & rect)This signal is emitted when the rectrect in the current frame has been updated. You can callcurrentImage() orcurrentPixmap() to get a copy of the updated frame.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.