CopperSpice API  1.7.2
QMovie Class Reference

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

Inheritance diagram for QMovie:
QObject

Public Types

enum  CacheMode
 
enum  MovieState
 

Public Signals

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)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

bool jumpToNextFrame ()
 
void setPaused (bool paused)
 
void setSpeed (int percentSpeed)
 
void start ()
 
void stop ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QMovie (const QString &fileName, const QString &format=QString (), QObject *parent=nullptr)
 
 QMovie (QIODevice *device, const QString &format=QString (), QObject *parent=nullptr)
 
 QMovie (QObject *parent=nullptr)
 
 ~QMovie ()
 
QColor backgroundColor () const
 
CacheMode cacheMode () const
 
int currentFrameNumber () const
 
QImage currentImage () const
 
QPixmap currentPixmap () const
 
QIODevicedevice () const
 
QString fileName () const
 
QString 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 QString &format)
 
void setScaledSize (const QSize &size)
 
int speed () const
 
MovieState state () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Static Public Methods

static QList< QStringsupportedFormats ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Properties

 cacheMode
 
 speed
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The QMovie class is a convenience class for playing movies with QImageReader. This class is used to show simple animations without sound. If you want to display video and media content use the classes in CsMultimedia. Refer to Multimedia for additional information.

To create a QMovie object, pass 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

Member Enumeration Documentation

This enum describes the different cache modes of QMovie.

ConstantValueDescription
QMovie::CacheNone0No frames are cached (the default).
QMovie::CacheAll1All frames are cached.

This enum describes the different states of QMovie.

ConstantValueDescription
QMovie::NotRunning0 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::Paused1 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::Running2 Movie is running.

Constructor & Destructor Documentation

QMovie::QMovie ( QObject parent = nullptr)
explicit

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

See also
setFileName(), setDevice(), setFormat()
QMovie::QMovie ( QIODevice device,
const QString format = QString(),
QObject parent = nullptr 
)
explicit

Constructs a QMovie object. The parent object is passed to QObject's constructor.

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

QMovie::QMovie ( const QString fileName,
const QString format = QString(),
QObject parent = nullptr 
)
explicit

Constructs a QMovie object. The parent object is passed to QObject's constructor.

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

QMovie::~QMovie ( )

Destroys the QMovie object.

Method Documentation

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()
CacheMode QMovie::cacheMode ( ) const

Property documentation pending.

int QMovie::currentFrameNumber ( ) const

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

QImage QMovie::currentImage ( ) const

Returns the current frame as a QImage.

See also
currentPixmap(), updated()
QPixmap QMovie::currentPixmap ( ) const

Returns the current frame as a QPixmap.

See also
currentImage(), updated()
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(), fileName()
void QMovie::error ( QImageReader::ImageReaderError  error)
signal

This signal is emitted by QMovie when the error 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(), device()
void QMovie::finished ( )
signal

This signal is emitted when the movie has finished.

See also
QMovie::stop()
QString QMovie::format ( ) const

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

See also
setFormat()
void QMovie::frameChanged ( int  frameNumber)
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.

int QMovie::frameCount ( ) const

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

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

See also
currentImage(), currentPixmap()
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.

bool QMovie::jumpToFrame ( int  frameNumber)

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

bool QMovie::jumpToNextFrame ( )
slot

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

int QMovie::loopCount ( ) const

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.

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

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

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

QSize QMovie::scaledSize ( )

Returns the scaled size of frames.

See also
setScaledSize(), QImageReader::scaledSize()
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::setCacheMode ( CacheMode  mode)

Property documentation pending.

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(), 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(), setFormat()
void QMovie::setFormat ( const QString 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(), QImageReader::supportedImageFormats()
void QMovie::setPaused ( bool  paused)
slot

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
state()
void QMovie::setScaledSize ( const QSize size)

Sets the scaled frame size to size.

See also
scaledSize(), QImageReader::setScaledSize()
void QMovie::setSpeed ( int  percentSpeed)
slot

Property documentation pending.

int QMovie::speed ( ) const

Property documentation pending.

void QMovie::start ( )
slot

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 method is equivalent to calling setPaused(false). If QMovie is already in the Running state, this function does nothing.

See also
stop(), setPaused()
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, stateChanged()
void QMovie::stateChanged ( QMovie::MovieState  state)
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 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. If QMovie is already in the NotRunning state, this function does nothing.

See also
start(), setPaused()
QList< QString > QMovie::supportedFormats ( )
static

Returns the list of image formats supported by QMovie.

See also
QImageReader::supportedImageFormats()
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 currentImage() or currentPixmap() to get a copy of the updated frame.

Property Documentation

QMovie::cacheMode

This property holds the movie's cache mode.

Caching frames can be useful when the underlying animation format handler that QMovie 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, a QMovie 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 to CacheNone.

See also
QMovie::CacheMode
PropertiesClass Methods
read cacheMode
write setCacheMode
QMovie::speed

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
PropertiesClass Methods
read speed
write setSpeed