QGraphicsVideoItem 类提供图形项所显示的视频产生自 QMediaPlayer or QCamera . 更多...
头: | #include <QGraphicsVideoItem> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS MultimediaWidgets)
target_link_libraries(mytarget PRIVATE Qt6::MultimediaWidgets) |
qmake: | QT += multimediawidgets |
继承: | QGraphicsObject |
|
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 |
QVideoSink * | videoSink () const |
virtual QRectF | boundingRect () const override |
virtual void | paint (QPainter * painter , const QStyleOptionGraphicsItem * option , QWidget * widget = nullptr) override |
virtual int | type () const override |
void | nativeSizeChanged (const QSizeF & size ) |
附加 QGraphicsVideoItem 到 QMediaPlayer or QCamera 允许它显示该媒体对象的视频 (或图像输出)。
player = new QMediaPlayer(this); QGraphicsVideoItem *item = new QGraphicsVideoItem; player->setVideoOutput(item); graphicsView->scene()->addItem(item); graphicsView->show(); player->setSource(QUrl("http://example.com/myclip4.ogv")); player->play();
注意 :每次只可以把单个显示输出附加到媒体对象。
另请参阅 QMediaPlayer , QVideoWidget ,和 QCamera .
如何比例缩放视频以拟合图形项的大小。
访问函数:
Qt::AspectRatioMode | aspectRatioMode () const |
void | setAspectRatioMode (Qt::AspectRatioMode mode ) |
[read-only]
nativeSize
: const
QSizeF
此特性保持视频的本机大小。
访问函数:
QSizeF | nativeSize () const |
通知程序信号:
void | nativeSizeChanged (const QSizeF & size ) |
此特性保持视频项的偏移。
QGraphicsVideoItem 将使用其左上角的偏移绘制视频。
访问函数:
QPointF | offset () const |
void | setOffset (const QPointF & offset ) |
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 ) |
[read-only]
videoSink
:
QVideoSink
* const
Returns the underlying video sink 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); item->videoSink()->setVideoFrame(QVideoFrame(img));
访问函数:
QVideoSink * | videoSink () const | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 QMediaPlayer::setVideoOutput .
[explicit]
QGraphicsVideoItem::
QGraphicsVideoItem
(
QGraphicsItem
*
parent
= nullptr)
构造显示视频的图形项。
The parent 会被传递给 QGraphicsItem .
[virtual noexcept]
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).
[override virtual]
int
QGraphicsVideoItem::
type
() const
重实现: QGraphicsItem::type() const .
Returns an int representing the type of the video item.