我必须编写一个简单的视频播放器,可以在特定时间显示一些字幕、链接或图片(如 YouTube 上的图片)。我不知道如何使用 QVideoWidget 显示任何内容。我找不到任何有用的课程来做到这一点。您能给我一些建议吗?
我按照你的方式做了,但是在我加载任何视频后,QLabel 消失了......
player->setVideoOutput(vw);
playlistView->setMaximumWidth(200);
playlistView->setMinimumWidth(300);
window = new QWidget;
Playerlayout = new QGridLayout;
subtitleWidget = new QLabel;
subtitleWidget->setMaximumWidth(1000);
subtitleWidget->setMaximumHeight(100);
subtitleWidget->setStyleSheet("QLabel {background-color : red; color
blue;}");
subtitleWidget->setAlignment(Qt::AlignCenter | Qt::AlignBottom);
subtitleWidget->setWordWrap(true);
subtitleWidget->setText("example subtitle");
Playerlayout->addWidget(vw,0,0);
Playerlayout->addWidget(subtitleWidget,0,0);
Playerlayout->addWidget(playlistView,0,1,1,2);
If QVideoWidget
不直接提供您需要的内容,那么您始终可以设置覆盖。
基本布局项目层次结构类似于......
QWidget
layout
QVideoWidget
subtitle_widget
在这种情况下,布局可以是QStackedLayout http://doc.qt.io/qt-5/qstackedlayout.html使用堆叠模式QStackedLayout::StackAll http://doc.qt.io/qt-5/qstackedlayout.html#StackingMode-enum or a QGridLayout http://doc.qt.io/qt-5/qgridlayout.html与两个QVideoWidget
和subtitle_widget
占据相同的单元格但具有正确的 z 顺序。
与QGridLayout
...
auto *w = new QWidget;
auto *l = new QGridLayout(w);
auto *video_widget = new QVideoWidget;
auto *subtitle_widget = new QLabel;
/*
* Subtitles will be shown at the bottom of the 'screen'
* and centred horizontally.
*/
subtitle_widget->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
subtitle_widget->setWordWrap(true);
/*
* Place both the video and subtitle widgets in cell (0, 0).
*/
l->addWidget(video_widget, 0, 0);
l->addWidget(subtitle_widget, 0, 0);
现在只需调用即可显示字幕等subtitle_widget->setText(...)
在适当的时间。
相同的方法可以很容易地扩展到覆盖其他类型的信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)