Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QMovie Class

TheQMovie class is a convenience class for playing movies withQImageReader.More...

Header:#include <QMovie>
Inherits:QObject

Public Types

enumCacheMode { CacheNone, CacheAll }
enumMovieState { NotRunning, Paused, Running }

Properties

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()
QColorbackgroundColor() const
CacheModecacheMode() const
intcurrentFrameNumber() const
QImagecurrentImage() const
QPixmapcurrentPixmap() const
QIODevice *device() const
QStringfileName() const
QByteArrayformat() const
intframeCount() const
QRectframeRect() const
boolisValid() const
booljumpToFrame(int frameNumber)
intloopCount() const
intnextFrameDelay() const
QSizescaledSize()
voidsetBackgroundColor(const QColor & color)
voidsetCacheMode(CacheMode mode)
voidsetDevice(QIODevice * device)
voidsetFileName(const QString & fileName)
voidsetFormat(const QByteArray & format)
voidsetScaledSize(const QSize & size)
intspeed() const
MovieStatestate() const
  • 29 public functions inherited fromQObject

Public Slots

booljumpToNextFrame()
voidsetPaused(bool paused)
voidsetSpeed(int percentSpeed)
voidstart()
voidstop()
  • 1 public slot inherited fromQObject

Signals

voiderror(QImageReader::ImageReaderError error)
voidfinished()
voidframeChanged(int frameNumber)
voidresized(const QSize & size)
voidstarted()
voidstateChanged(QMovie::MovieState state)
voidupdated(const QRect & rect)

Static Public Members

QList<QByteArray>supportedFormats()
  • 7 static public members inherited fromQObject

Additional Inherited Members

  • 8 protected functions inherited fromQObject

Detailed Description

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:

QLabel label;QMovie*movie=newQMovie("animations/fire.gif");label.setMovie(movie);movie->start();

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.

Member Type Documentation

enum QMovie::CacheMode

This enum describes the different cache modes ofQMovie.

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

enum QMovie::MovieState

This enum describes the different states ofQMovie.

ConstantValueDescription
QMovie::NotRunning0The movie is not running. This isQMovie's initial state, and the state it enters afterstop() has been called or the movie is finished.
QMovie::Paused1The 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::Running2The movie is running.

Property Documentation

cacheMode :CacheMode

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:

CacheModecacheMode() const
voidsetCacheMode(CacheMode mode)

See alsoQMovie::CacheMode.

speed :int

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:

intspeed() const
voidsetSpeed(int percentSpeed)

Member Function Documentation

QMovie::QMovie(QObject * parent = 0)

Constructs aQMovie object, passing theparent object toQObject's constructor.

See alsosetFileName(),setDevice(), andsetFormat().

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

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.

QMovie::QMovie(constQString & fileName, constQByteArray & format = QByteArray(),QObject * parent = 0)

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.

QMovie::~QMovie()

Destructs theQMovie object.

QColor QMovie::backgroundColor() const

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

See alsosetBackgroundColor().

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 aQImage.

See alsocurrentPixmap() andupdated().

QPixmap QMovie::currentPixmap() const

Returns the current frame as aQPixmap.

See alsocurrentImage() andupdated().

QIODevice * QMovie::device() const

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.

QString QMovie::fileName() const

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:

connect(movie,static_cast<void(QMovie::*)()>(&QMovie::finished),[=](){/* ... */ });

See alsoQMovie::stop().

QByteArray QMovie::format() const

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.

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 invalidQRect is returned.

See alsocurrentImage() andcurrentPixmap().

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 numberframeNumber. Returns true on success; otherwise returns false.

[slot]bool QMovie::jumpToNextFrame()

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.

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.

int QMovie::nextFrameDelay() const

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.

QSize QMovie::scaledSize()

Returns the scaled size of frames.

This function was introduced in Qt 4.1.

See alsosetScaledSize() andQImageReader::scaledSize().

void QMovie::setBackgroundColor(constQColor & color)

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

See alsobackgroundColor().

void QMovie::setDevice(QIODevice * device)

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

See alsodevice() andsetFormat().

void QMovie::setFileName(constQString & fileName)

Sets the name of the file thatQMovie reads image data from, tofileName.

See alsofileName(),setDevice(), andsetFormat().

void QMovie::setFormat(constQByteArray & format)

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

See alsopaused() andstate().

void QMovie::setScaledSize(constQSize & size)

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.

MovieState QMovie::state() const

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.


[8]ページ先頭

©2009-2025 Movatter.jp