QMovie 類

QMovie 類是用於播放影片的方便類采用 QImageReader . 更多...

頭: #include <QMovie>
qmake: QT += gui
繼承: QObject

公共類型

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

特性

公共函數

QMovie (const QString & fileName , const QByteArray & format = QByteArray(), QObject * parent = nullptr)
QMovie (QIODevice * device , const QByteArray & format = QByteArray(), QObject * parent = nullptr)
QMovie (QObject * parent = nullptr)
virtual ~QMovie ()
QColor backgroundColor () const
QMovie::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 )
QImageReader::ImageReaderError lastError () const
QString lastErrorString () const
int loopCount () const
int nextFrameDelay () const
QSize scaledSize ()
void setBackgroundColor (const QColor & color )
void setCacheMode (QMovie::CacheMode mode )
void setDevice (QIODevice * device )
void setFileName (const QString & fileName )
void setFormat (const QByteArray & format )
void setScaledSize (const QSize & size )
int speed () const
QMovie::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 ()

詳細描述

This class is used to show simple animations without sound. If you want to display video and media content, use the Qt Multimedia multimedia framework instead.

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 運行 state, and emit started () 和 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 ()。範例:

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 () 或 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 運行 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 ().

調用 supportedFormats () 為 QMovie 支持的格式列錶。

另請參閱 QLabel , QImageReader ,和 影片範例 .

成員類型文檔編製

enum QMovie:: CacheMode

此枚舉描述不同緩存模式,為 QMovie .

常量 描述
QMovie::CacheNone 0 沒有幀被緩存 (默認)。
QMovie::CacheAll 1 所有幀都被緩存。

enum QMovie:: MovieState

此枚舉描述不同狀態為 QMovie .

常量 描述
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 () 或 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) 被調用。
QMovie::Running 2 The movie is running.

特性文檔編製

cacheMode : CacheMode

此特性保持影片的緩存模式

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.

默認情況下,此特性被設為 CacheNone .

訪問函數:

QMovie::CacheMode cacheMode () const
void setCacheMode (QMovie::CacheMode mode )

另請參閱 QMovie::CacheMode .

speed : int

此特性保持影片的速度

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
					

訪問函數:

int speed () const
void setSpeed (int percentSpeed )

成員函數文檔編製

QMovie:: QMovie (const QString & fileName , const QByteArray & format = QByteArray(), QObject * parent = nullptr)

Constructs a QMovie object. QMovie will use read image data from fileName 。若 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 對象被傳遞給 QObject 的構造函數。

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

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 對象被傳遞給 QObject 的構造函數。

QMovie:: QMovie ( QObject * parent = nullptr)

Constructs a QMovie object, passing the parent 對象到 QObject 的構造函數。

另請參閱 setFileName (), setDevice (),和 setFormat ().

[signal] void QMovie:: error ( QImageReader::ImageReaderError error )

此信號發射由 QMovie when the error error occurred during playback. QMovie will stop the movie, and enter QMovie::NotRunning 狀態。

另請參閱 lastError () 和 lastErrorString ().

[signal] void QMovie:: finished ()

This signal is emitted when the movie has finished.

另請參閱 QMovie::stop ().

[signal] void QMovie:: frameChanged ( int frameNumber )

This signal is emitted when the frame number has changed to frameNumber 。可以調用 currentImage () 或 currentPixmap () to get a copy of the frame.

該函數在 Qt 4.1 引入。

[slot] bool QMovie:: jumpToNextFrame ()

Jumps to the next frame. Returns true 當成功時;否則返迴 false .

[signal] void QMovie:: resized (const QSize & size )

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

[slot] void QMovie:: setPaused ( bool paused )

paused 為 True, QMovie 將進入 Paused state and emit stateChanged (Paused); otherwise it will enter 運行 state and emit stateChanged (Running).

另請參閱 state ().

[slot] void QMovie:: start ()

Starts the movie. QMovie 將進入 運行 state, and start emitting updated () 和 resized () as the movie progresses.

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

另請參閱 stop () 和 setPaused ().

[signal] void QMovie:: started ()

此信號發射後於 QMovie::start () has been called, and QMovie has entered QMovie::Running 狀態。

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

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

另請參閱 QMovie::state ().

[slot] void QMovie:: stop ()

停止影片。 QMovie 進入 NotRunning state, and stops emitting updated () 和 resized ()。若 start () is called again, the movie will restart from the beginning.

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

另請參閱 start () 和 setPaused ().

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

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

[虛擬] QMovie:: ~QMovie ()

銷毀 QMovie 對象。

QColor QMovie:: backgroundColor () const

Returns the background color of the movie. If no background color has been assigned, an invalid QColor 被返迴。

另請參閱 setBackgroundColor ().

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

返迴當前幀,作為 QImage .

另請參閱 currentPixmap () 和 updated ().

QPixmap QMovie:: currentPixmap () const

返迴當前幀,作為 QPixmap .

另請參閱 currentImage () 和 updated ().

QIODevice *QMovie:: device () const

Returns the device QMovie reads image data from. If no device has currently been assigned, nullptr 被返迴。

另請參閱 setDevice () 和 fileName ().

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 被返迴。

另請參閱 setFileName () 和 device ().

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.

另請參閱 setFormat ().

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 被返迴。

另請參閱 currentImage () 和 currentPixmap ().

bool QMovie:: isValid () const

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

For information about why the movie is not valid, see lastError ().

bool QMovie:: jumpToFrame ( int frameNumber )

Jumps to frame number frameNumber 。返迴 true 當成功時;否則返迴 false .

QImageReader::ImageReaderError QMovie:: lastError () const

Returns the most recent error that occurred while attempting to read image data.

另請參閱 lastErrorString ().

QString QMovie:: lastErrorString () const

Returns a human-readable representation of the most recent error that occurred while attempting to read image data.

另請參閱 lastError ().

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.

Note that, if the image data comes from a sequential device (e.g. a socket), QMovie can only loop the movie if the cacheMode 被設為 QMovie::CacheAll .

int QMovie:: nextFrameDelay () const

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

QSize QMovie:: scaledSize ()

Returns the scaled size of frames.

該函數在 Qt 4.1 引入。

另請參閱 setScaledSize () 和 QImageReader::scaledSize ().

void QMovie:: setBackgroundColor (const QColor & color )

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

另請參閱 backgroundColor ().

void QMovie:: setDevice ( QIODevice * device )

把當前設備設為 device . QMovie will read image data from this device when the movie is running.

另請參閱 device () 和 setFormat ().

void QMovie:: setFileName (const QString & fileName )

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

另請參閱 fileName (), setDevice (),和 setFormat ().

void QMovie:: setFormat (const QByteArray & format )

Sets the format that QMovie will use when decoding image data, to format 。默認情況下, QMovie will attempt to guess the format of the image data.

可以調用 supportedFormats () 瞭解完整格式列錶 QMovie 支持。

另請參閱 format () 和 QImageReader::supportedImageFormats ().

void QMovie:: setScaledSize (const QSize & size )

Sets the scaled frame size to size .

該函數在 Qt 4.1 引入。

另請參閱 scaledSize () 和 QImageReader::setScaledSize ().

QMovie::MovieState QMovie:: state () const

返迴當前狀態,為 QMovie .

另請參閱 MovieState and stateChanged ().

[static] QList < QByteArray > QMovie:: supportedFormats ()

返迴圖像格式列錶支持通過 QMovie .

該函數在 Qt 4.1 引入。

另請參閱 QImageReader::supportedImageFormats ().