我必须写一个简单的视频播放器,可以在一定时间内显示一些字幕,链接或图片(如在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);
Run Code Online (Sandbox Code Playgroud)
如果QVideoWidget没有直接提供您需要的内容,那么您始终可以设置覆盖。
基本布局项目层次结构类似于......
QWidget
layout
QVideoWidget
subtitle_widget
Run Code Online (Sandbox Code Playgroud)
在这种情况下,布局可以是QStackedLayout使用堆叠模式QStackedLayout::StackAll,也QGridLayout可以是 和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);
Run Code Online (Sandbox Code Playgroud)
subtitle_widget->setText(...)现在只需在适当的时间调用即可显示字幕等。
相同的方法可以很容易地扩展到覆盖其他类型的信息。
| 归档时间: |
|
| 查看次数: |
537 次 |
| 最近记录: |