QVideoWidget Class

QVideoWidget 类提供了一个显示由媒体对象制作的视频的 widget。更多

Header: #include <QVideoWidget>
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 附加到QMediaPlayerQCamera 后,就可以显示该对象的视频或图像输出。

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

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

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

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

另请参阅 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)

Notifier 信号:

void fullScreenChanged(bool fullScreen)

成员函数 文档

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

构建一个新的视频部件。

parent 传递给QWidget

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

销毁视频 widget。

[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

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