QGraphicsVideoItem 类

QGraphicsVideoItem 类提供图形项所显示的视频产生自 QMediaObject . 更多...

头: #include <QGraphicsVideoItem>
qmake: QT += multimediawidgets
继承: QGraphicsObject and QMediaBindableInterface

特性

公共函数

QGraphicsVideoItem (QGraphicsItem * parent = nullptr)
virtual ~QGraphicsVideoItem ()
Qt::AspectRatioMode aspectRatioMode () const
QSizeF nativeSize () const
QPointF offset () const
void setAspectRatioMode (Qt::AspectRatioMode mode )
void setOffset (const QPointF & offset )
void setSize (const QSizeF & size )
QSizeF size () const
QAbstractVideoSurface * videoSurface () const

重实现公共函数

virtual QRectF boundingRect () const override
virtual QMediaObject * mediaObject () const override
virtual void paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = nullptr) override

信号

void nativeSizeChanged (const QSizeF & size )

详细描述

附加 QGraphicsVideoItem 到 QMediaObject allows it to display the video or image output of that media object. A QGraphicsVideoItem is attached to a media object by passing a pointer to the QMediaObject setMediaObject () 函数。

player = new QMediaPlayer(this);
QGraphicsVideoItem *item = new QGraphicsVideoItem;
player->setVideoOutput(item);
graphicsView->scene()->addItem(item);
graphicsView->show();
player->setMedia(QUrl("http://example.com/myclip4.ogv"));
player->play();
					

注意 :每次只可以把单个显示输出附加到媒体对象。

另请参阅 QMediaObject , QMediaPlayer ,和 QVideoWidget .

特性文档编制

aspectRatioMode : Qt::AspectRatioMode

如何比例缩放视频以拟合图形项的大小。

访问函数:

Qt::AspectRatioMode aspectRatioMode () const
void setAspectRatioMode (Qt::AspectRatioMode mode )

mediaObject : QMediaObject * const

This property holds the media object which provides the video displayed by a graphics item.

访问函数:

virtual QMediaObject * mediaObject () const override

nativeSize : const QSizeF

此特性保持视频的本机大小。

访问函数:

QSizeF nativeSize () const

通知程序信号:

void nativeSizeChanged (const QSizeF & size )

offset : QPointF

此特性保持视频项的偏移。

QGraphicsVideoItem 将使用其左上角的偏移绘制视频。

访问函数:

QPointF offset () const
void setOffset (const QPointF & offset )

size : QSizeF

This property holds the video item's size.

QGraphicsVideoItem will draw video scaled to fit size according to its fillMode.

访问函数:

QSizeF size () const
void setSize (const QSizeF & size )

videoSurface : QAbstractVideoSurface * const

Returns the underlying video surface that can render video frames to the current item. This property is never nullptr 。范例展示如何将视频帧渲染到 QGraphicsVideoItem :

QGraphicsVideoItem *item = new QGraphicsVideoItem;
graphicsView->scene()->addItem(item);
graphicsView->show();
QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);
QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32);
item->videoSurface()->start(format);
item->videoSurface()->present(img);
					

该特性在 Qt 5.15 引入。

访问函数:

QAbstractVideoSurface * videoSurface () const

另请参阅 QMediaPlayer::setVideoOutput .

成员函数文档编制

QGraphicsVideoItem:: QGraphicsVideoItem ( QGraphicsItem * parent = nullptr)

构造显示视频的图形项。

The parent 会被传递给 QGraphicsItem .

[signal] void QGraphicsVideoItem:: nativeSizeChanged (const QSizeF & size )

发射信号当本机 size 对于视频已改变。

注意: 通知程序信号对于特性 nativeSize .

[虚拟] QGraphicsVideoItem:: ~QGraphicsVideoItem ()

销毁视频图形项。

[override virtual] QRectF QGraphicsVideoItem:: boundingRect () const

重实现: QGraphicsItem::boundingRect () const.

[override virtual] void QGraphicsVideoItem:: paint ( QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = nullptr)

重实现: QGraphicsItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget).