|  | Home · All Classes · Modules

# QMovie Class Reference
[QtGui module]

The QMovie class is a convenience class for playing movies with QImageReader. More...

Inherits QObject.

### Types

- enum CacheMode { CacheNone, CacheAll }
- enum MovieState { NotRunning, Paused, Running }

### Methods

- __init__ (self, QObject parent = None)
- __init__ (self, QIODevice device, QByteArray format = QByteArray(), QObject parent = None)
- __init__ (self, QString fileName, QByteArray format = QByteArray(), QObject parent = None)
- QColor backgroundColor (self)
- CacheMode cacheMode (self)
- int currentFrameNumber (self)
- QImage currentImage (self)
- QPixmap currentPixmap (self)
- QIODevice device (self)
- QString fileName (self)
- QByteArray format (self)
- int frameCount (self)
- QRect frameRect (self)
- bool isValid (self)
- bool jumpToFrame (self, int frameNumber)
- bool jumpToNextFrame (self)
- int loopCount (self)
- int nextFrameDelay (self)
- QSize scaledSize (self)
- setBackgroundColor (self, QColor color)
- setCacheMode (self, CacheMode mode)
- setDevice (self, QIODevice device)
- setFileName (self, QString fileName)
- setFormat (self, QByteArray format)
- setPaused (self, bool paused)
- setScaledSize (self, QSize size)
- setSpeed (self, int percentSpeed)
- int speed (self)
- start (self)
- MovieState state (self)
- stop (self)

### Static Methods

- QByteArray-list supportedFormats ()

### Qt Signals

- void error (QImageReader::ImageReaderError)
- void finished ()
- void frameChanged (int)
- void resized (const QSize&)
- void started ()
- void stateChanged (QMovie::MovieState)
- void updated (const QRect&)

## Detailed Description

The QMovie class is a convenience class for playing movies with QImageReader.

First, create a QMovie object by passing either the name of a file or a pointer to a QIODevice containing an animated image format to QMovie's constructor. You can call isValid() to check if the image data is valid, before starting the movie. To start the movie, call start(). QMovie will enter Running state, and emit started() and stateChanged(). To get the current state of the movie, call state().

To display the movie in your application, you can pass your QMovie object to QLabel.setMovie(). Example:

     QLabel label;
     QMovie *movie = new QMovie("animations/fire.gif");

     label.setMovie(movie);
     movie->start();

Whenever a new frame is available in the movie, QMovie will emit updated(). If the size of the frame changes, resized() is emitted. You can call currentImage() or currentPixmap() to get a copy of the current frame. When the movie is done, QMovie emits finished(). If any error occurs during playback (i.e, the image file is corrupt), QMovie will emit error().

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 calling setPaused(true). QMovie will then enter Paused state and emit stateChanged(). If you call setPaused(false), QMovie will reenter Running state and start the movie again. To stop the movie, call stop().

Certain animation formats allow you to set the background color. You can call setBackgroundColor() to set the color, or backgroundColor() 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 call loopCount() 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 calling setCacheMode().

Call supportedFormats() for a list of formats that QMovie supports.

See also QLabel, QImageReader, and Movie Example.

## Type Documentation

### QMovie.CacheMode

This enum describes the different cache modes of QMovie.

Constant | Value | Description
--- | --- | ---
`QMovie.CacheNone` | `0` | No frames are cached (the default).
`QMovie.CacheAll` | `1` | All frames are cached.

### QMovie.MovieState

This enum describes the different states of QMovie.

Constant | Value | Description
--- | --- | ---
`QMovie.NotRunning` | `0` | The movie is not running. This is QMovie's initial state, and the state it enters after stop() has been called or the movie is finished.
`QMovie.Paused` | `1` | The movie is paused, and QMovie stops emitting updated() or resized(). This state is entered after calling pause() or setPaused(true). The current frame number it kept, and the movie will continue with the next frame when unpause() or setPaused(false) is called.
`QMovie.Running` | `2` | The movie is running.

## Method Documentation

### QMovie.__init__ (self, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QMovie object, passing the parent object to QObject's constructor.

See also setFileName(), setDevice(), and setFormat().

### QMovie.__init__ (self, QIODevice device, QByteArray format = QByteArray(), QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QMovie object. QMovie will use read image data from device, which it assumes is open and readable. If format is not empty, QMovie will use the image format format for decoding the image data. Otherwise, QMovie will attempt to guess the format.

The parent object is passed to QObject's constructor.

### QMovie.__init__ (self, QString fileName, QByteArray format = QByteArray(), QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QMovie object. QMovie will use read image data from fileName. If format is not empty, QMovie will use the image format format for decoding the image data. Otherwise, QMovie will attempt to guess the format.

The parent object is passed to QObject's constructor.

### QColor QMovie.backgroundColor (self)

Returns the background color of the movie. If no background color has been assigned, an invalid QColor is returned.

See also setBackgroundColor().

### CacheMode QMovie.cacheMode (self)

### int QMovie.currentFrameNumber (self)

Returns the sequence number of the current frame. The number of the first frame in the movie is 0.

### QImage QMovie.currentImage (self)

Returns the current frame as a QImage.

See also currentPixmap() and updated().

### QPixmap QMovie.currentPixmap (self)

Returns the current frame as a QPixmap.

See also currentImage() and updated().

### QIODevice QMovie.device (self)

Returns the device QMovie reads image data from. If no device has currently been assigned, 0 is returned.

See also setDevice() and fileName().

### QString QMovie.fileName (self)

Returns the name of the file that QMovie reads 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 setFileName() and device().

### QByteArray QMovie.format (self)

Returns the format that QMovie uses when decoding image data. If no format has been assigned, an empty QByteArray() is returned.

See also setFormat().

### int QMovie.frameCount (self)

Returns the number of frames in the movie.

Certain animation formats do not support this feature, in which case 0 is returned.

### QRect QMovie.frameRect (self)

Returns the rect of the last frame. If no frame has yet been updated, an invalid QRect is returned.

See also currentImage() and currentPixmap().

### bool QMovie.isValid (self)

Returns true if the movie is valid (e.g., the image data is readable and the image format is supported); otherwise returns false.

### bool QMovie.jumpToFrame (self, int frameNumber)

Jumps to frame number frameNumber. Returns true on success; otherwise returns false.

### bool QMovie.jumpToNextFrame (self)

This method is also a Qt slot with the C++ signature `bool jumpToNextFrame()`.

Jumps to the next frame. Returns true on success; otherwise returns false.

### int QMovie.loopCount (self)

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 the cacheMode is set to QMovie.CacheAll.

### int QMovie.nextFrameDelay (self)

Returns the number of milliseconds QMovie will wait before updating the next frame in the animation.

### QSize QMovie.scaledSize (self)

Returns the scaled size of frames.

This function was introduced in Qt 4.1.

See also setScaledSize() and QImageReader.scaledSize().

### QMovie.setBackgroundColor (self, QColor color)

For image formats that support it, this function sets the background color to color.

See also backgroundColor().

### QMovie.setCacheMode (self, CacheMode mode)

### QMovie.setDevice (self, QIODevice device)

Sets the current device to device. QMovie will read image data from this device when the movie is running.

See also device() and setFormat().

### QMovie.setFileName (self, QString fileName)

Sets the name of the file that QMovie reads image data from, to fileName.

See also fileName(), setDevice(), and setFormat().

### QMovie.setFormat (self, QByteArray format)

Sets the format that QMovie will use when decoding image data, to format. By default, QMovie will attempt to guess the format of the image data.

You can call supportedFormats() for the full list of formats QMovie supports.

See also format() and QImageReader.supportedImageFormats().

### QMovie.setPaused (self, bool paused)

This method is also a Qt slot with the C++ signature `void setPaused(bool)`.

If paused is true, QMovie will enter Paused state and emit stateChanged(Paused); otherwise it will enter Running state and emit stateChanged(Running).

See also paused() and state().

### QMovie.setScaledSize (self, QSize size)

Sets the scaled frame size to size.

This function was introduced in Qt 4.1.

See also scaledSize() and QImageReader.setScaledSize().

### QMovie.setSpeed (self, int percentSpeed)

### int QMovie.speed (self)

### QMovie.start (self)

This method is also a Qt slot with the C++ signature `void start()`.

Starts the movie. QMovie will enter Running state, and start emitting updated() and resized() as the movie progresses.

If QMovie is in the Paused state, this function is equivalent to calling setPaused(false). If QMovie is already in the Running state, this function does nothing.

See also stop() and setPaused().

### MovieState QMovie.state (self)

Returns the current state of QMovie.

See also MovieState and stateChanged().

### QMovie.stop (self)

This method is also a Qt slot with the C++ signature `void stop()`.

Stops the movie. QMovie enters NotRunning state, and stops emitting updated() and resized(). If start() is called again, the movie will restart from the beginning.

If QMovie is already in the NotRunning state, this function does nothing.

See also start() and setPaused().

### QByteArray-list QMovie.supportedFormats ()

Returns the list of image formats supported by QMovie.

This function was introduced in Qt 4.1.

See also QImageReader.supportedImageFormats().

## Qt Signal Documentation

### void error (QImageReader::ImageReaderError)

This is the default overload of this signal.

This signal is emitted by QMovie when the error error occurred during playback. QMovie will stop the movie, and enter QMovie.NotRunning state.

### void finished ()

This is the default overload of this signal.

This signal is emitted when the movie has finished.

See also QMovie.stop().

### void frameChanged (int)

This is the default overload of this signal.

This signal is emitted when the frame number has changed to frameNumber. You can call currentImage() or currentPixmap() to get a copy of the frame.

This function was introduced in Qt 4.1.

### void resized (const QSize&)

This is the default overload of this signal.

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 call currentImage() or currentPixmap() to get a copy of the updated frame.

### void started ()

This is the default overload of this signal.

This signal is emitted after QMovie.start() has been called, and QMovie has entered QMovie.Running state.

### void stateChanged (QMovie::MovieState)

This is the default overload of this signal.

This signal is emitted every time the state of the movie changes. The new state is specified by state.

See also QMovie.state().

### void updated (const QRect&)

This is the default overload of this signal.

This signal is emitted when the rect rect in the current frame has been updated. You can call currentImage() or currentPixmap() to get a copy of the updated frame.