本页内容

QVideoWidget Class

QVideoWidget 类提供了一个控件,用于显示由媒体对象生成的视频。更多内容...

头文件: #include <qvideowidget.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS MultimediaWidgets)
target_link_libraries(mytarget PRIVATE Qt6::MultimediaWidgets)
qmake: QT += multimediawidgets
继承自: QWidget

属性

公共函数

QVideoWidget(QWidget *parent = nullptr)
virtual ~QVideoWidget() override
Qt::AspectRatioMode aspectRatioMode() const
bool isFullScreen() const
QVideoSink *videoSink() const

重新实现的公共函数

virtual QSize sizeHint() const override

公共插槽

void setAspectRatioMode(Qt::AspectRatioMode mode)
void setFullScreen(bool fullScreen)

信号

void aspectRatioModeChanged(Qt::AspectRatioMode mode)
void fullScreenChanged(bool fullScreen)

重新实现的受保护函数

virtual bool event(QEvent *event) override
virtual void hideEvent(QHideEvent *event) override
virtual void moveEvent(QMoveEvent *event) override
virtual void resizeEvent(QResizeEvent *event) override
virtual void showEvent(QShowEvent *event) override

详细说明

将 QVideoWidget 连接到QMediaPlayer 或QCamera 后,它即可显示该对象的视频或图像输出。

player = new QMediaPlayer;
player->setSource(QUrl("http://example.com/myclip1.mp4"));

videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);

videoWidget->show();
player->play();

注意:一个媒体对象一次只能连接一个显示输出。

警告: eglfs 平台插件不支持QVideoWidget 。

另请参阅 QCamera 、QMediaPlayer 和QGraphicsVideoItem 。

属性文档

aspectRatioMode : Qt::AspectRatioMode

视频如何根据其宽高比进行缩放。

访问函数:

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

通知信号:

void aspectRatioModeChanged(Qt::AspectRatioMode mode)

fullScreen : bool

该属性用于指定视频显示是限制在窗口内,还是全屏显示。

访问函数:

bool isFullScreen() const
void setFullScreen(bool fullScreen)

通知器信号:

void fullScreenChanged(bool fullScreen)

成员函数文档

[explicit] QVideoWidget::QVideoWidget(QWidget *parent = nullptr)

创建一个新的视频控件。

将parent 传递给QWidget 。

[override virtual noexcept] QVideoWidget::~QVideoWidget()

销毁一个视频控件。

[override virtual protected] bool QVideoWidget::event(QEvent *event)

重写自:QWidget::event(QEvent *event)。

当前事件event 。返回基类函数QWidget::event(QEvent *event) 的返回值。

[override virtual protected] void QVideoWidget::hideEvent(QHideEvent *event)

重写:QWidget::hideEvent(QHideEvent *event)。

处理隐藏事件event 。

[override virtual protected] void QVideoWidget::moveEvent(QMoveEvent *event)

重写:QWidget::moveEvent(QMoveEvent *event)。

处理移动操作event 。

[override virtual protected] void QVideoWidget::resizeEvent(QResizeEvent *event)

重写自:QWidget::resizeEvent(QResizeEvent *event)。

处理event 的调整大小事件。

[override virtual protected] void QVideoWidget::showEvent(QShowEvent *event)

重写:QWidget::showEvent(QShowEvent *event)。

处理event 的显示操作。

[override virtual] QSize QVideoWidget::sizeHint() const

重新实现了属性QWidget::sizeHint 的访问函数。

返回当前后端的大小提示(如有),否则返回来自QWidget 的大小提示。

[invokable] QVideoSink *QVideoWidget::videoSink() const

返回QVideoSink 实例。

注意: 可以通过元对象系统以及从 QML 中调用此 函数。请参阅Q_INVOKABLE 。

© 2026 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.