QGraphicsVideoItem Class

The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaPlayer or QCamera. More...

Header: #include <QGraphicsVideoItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS MultimediaWidgets)
target_link_libraries(mytarget PRIVATE Qt6::MultimediaWidgets)
qmake: QT += multimediawidgets
Inherits: QGraphicsObject

Public Types

enum anonymous { Type }


Public Functions

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

Reimplemented Public Functions

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)

Protected Variables

QGraphicsVideoItemPrivate *d_ptr

Detailed Description

Attaching a QGraphicsVideoItem to a QMediaPlayer or QCamera allows it to display the video or image output of that media object.

player = new QMediaPlayer(this);

QGraphicsVideoItem *item = new QGraphicsVideoItem;


Note: Only a single display output can be attached to a media object at one time.

See also QMediaPlayer, QVideoWidget, and QCamera.

Member Type Documentation

enum QGraphicsVideoItem::anonymous

Property Documentation

aspectRatioMode : Qt::AspectRatioMode

how a video is scaled to fit the graphics item's size.

Access functions:

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

[read-only] nativeSize : const QSizeF

This property holds the native size of the video.

Access functions:

QSizeF nativeSize() const

Notifier signal:

void nativeSizeChanged(const QSizeF &size)

offset : QPointF

This property holds the video item's offset.

QGraphicsVideoItem will draw video using the offset for its top left corner.

Access functions:

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.

Access functions:

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. Example of how to render video frames to QGraphicsVideoItem:

QGraphicsVideoItem *item = new QGraphicsVideoItem;
QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);

Access functions:

QVideoSink *videoSink() const[see note below]

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

See also QMediaPlayer::setVideoOutput.

Member Function Documentation

QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent = nullptr)

Constructs a graphics item that displays video.

The parent is passed to QGraphicsItem.

[virtual] QGraphicsVideoItem::~QGraphicsVideoItem()

Destroys a video graphics item.

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

Reimplements: QGraphicsItem::boundingRect() const.

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

Reimplements: QGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget).

[override virtual] int QGraphicsVideoItem::type() const

Member Variable Documentation

QGraphicsVideoItemPrivate *QGraphicsVideoItem::d_ptr

© 2022 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 the GNU 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.