|  | Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions |

# QMovie Class Reference

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

    #include <QMovie>

Part of the QtGui module.

Inherits QObject.

- List of all members, including inherited members

### Public Types

- enum MovieState { NotRunning, Paused, Running }

### Public Functions

- 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
- int currentFrameNumber () const
- QIODevice * device () const
- QString fileName () const
- QByteArray format () const
- int frameCount () const
- QImage frameImage () const
- QPixmap framePixmap () const
- QRect frameRect () const
- bool isPaused () const
- bool isRunning () const
- bool isValid () const
- int loopCount () const
- int nextFrameDelay () const
- void setBackgroundColor ( const QColor & color )
- void setDevice ( QIODevice * device )
- void setFileName ( const QString & fileName )
- void setFormat ( const QByteArray & format )
- void setPaused ( bool paused )
- void setSpeed ( int percentSpeed )
- int speed () const
- MovieState state () const

- 28 public functions inherited from QObject

### Public Slots

- void pause ()
- void start ()
- void stop ()
- void unpause ()

- 1 public slot inherited from QObject

### Signals

- void error ()
- void finished ()
- void resized ( const QSize & size )
- void started ()
- void stateChanged ( MovieState state )
- void updated ( const QRect & rect )

- 1 signal inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 4 static public members inherited from QObject
- 7 protected functions inherited from QObject

## Detailed Description

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

QMovie is a convenience class that uses QImageReader internally to play movies.

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 frameImage() or framePixmap() 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 pause(). QMovie will then enter Paused state and emit stateChanged(). If you call unpause(), 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.

See also QLabel and QImageReader.

## Member Type Documentation

### enum 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.

## Member Function Documentation

### QMovie::QMovie ( QObject * parent = 0 )

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

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

### QMovie::QMovie ( QIODevice * device, const QByteArray & format = QByteArray(), QObject * parent = 0 )

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::QMovie ( const QString & fileName, const QByteArray & format = QByteArray(), QObject * parent = 0 )

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.

### QMovie::~QMovie ()

Destructs the QMovie object.

### QColor QMovie::backgroundColor () const

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

See also setBackgroundColor().

### int QMovie::currentFrameNumber () const

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

### QIODevice * QMovie::device () const

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

See also setDevice() and fileName().

### void QMovie::error () `[signal]`

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

### QString QMovie::fileName () const

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().

### void QMovie::finished () `[signal]`

This signal is emitted when the movie has finished.

See also QMovie::stop().

### QByteArray QMovie::format () const

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 () const

Returns the number of frames in the movie.

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

### QImage QMovie::frameImage () const

Returns the current frame as a QImage.

See also framePixmap() and updated().

### QPixmap QMovie::framePixmap () const

Returns the current frame as a QPixmap.

See also frameImage() and updated().

### QRect QMovie::frameRect () const

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

See also frameImage() and framePixmap().

### bool QMovie::isPaused () const

Returns true if the movie is paused; otherwise returns false.

Same as state() == QMovie::Paused.

See also isRunning().

### bool QMovie::isRunning () const

Returns true if QMovie is in Running state.

Same as state() == QMovie::Running.

### bool QMovie::isValid () const

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

### int QMovie::loopCount () const

Returns the number of times the movie will loop before it finishes.

### int QMovie::nextFrameDelay () const

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

### void QMovie::pause () `[slot]`

Pauses the movie. QMovie will enter Paused state, and stop emitting updated() and resized() until the movie is unpaused.

See also unpause(), setPaused(), and state().

### void QMovie::resized ( const QSize & size ) `[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 frameImage() or framePixmap() to get a copy of the updated frame.

### void QMovie::setBackgroundColor ( const QColor & color )

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

See also backgroundColor().

### void QMovie::setDevice ( 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().

### void QMovie::setFileName ( const QString & fileName )

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

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

### void QMovie::setFormat ( const 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.

See also QImageReader::supportedImageFormats().

### void QMovie::setPaused ( bool paused )

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 isPaused() and state().

### void QMovie::setSpeed ( int percentSpeed )

Sets the speed of the movie to percentSpeed, in percentage of the original speed. Example:

        QMovie movie("racecar.gif");
        movie.setSpeed(200); // 2x speed

See also speed().

### int QMovie::speed () const

Returns the current speed of the movie, in percentage of the original movie speed. By default, 100 is returned (i.e., 100% of the original speed).

See also setSpeed().

### void QMovie::start () `[slot]`

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

See also stop() and pause().

### void QMovie::started () `[signal]`

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

### MovieState QMovie::state () const

Returns the current state of QMovie.

See also MovieState and stateChanged().

### void QMovie::stateChanged ( MovieState state ) `[signal]`

This signal is emitted every time QMovie's state changes. state is the new state of QMovie.

See also QMovie::state().

### void QMovie::stop () `[slot]`

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.

See also start() and pause().

### void QMovie::unpause () `[slot]`

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

See also pause() and stop().

### void QMovie::updated ( const QRect & rect ) `[signal]`

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