python qt,在另一个小部件(声子)上方显示文本/标签 [英] python qt, display text/label above another widget(phonon)

查看:57
本文介绍了python qt,在另一个小部件(声子)上方显示文本/标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PySide 制作视频播放器,它是与 Qt 框架的 Python 绑定.我正在使用声子(一个模块)来显示视频,我想在视频上方显示文本作为字幕.如何将另一个小部件放在我的声子小部件上方.opengl 是一种选择吗?

I'm making a video player using PySide which is a python bind to the Qt framework. I'm using phonon(a module) to display the video and I want to display text above the video as a subtitle. How can I put another widget above my phonon widget. Is opengl an option?

推荐答案

如果您只是创建标签并将声子小部件设置为父级,则标签应显示在其上方.

If you just create your label and set the phonon widget as the parent, the label should appear over it.

QLabel *label = new QLabel(phononWidget);
label->setText("Text over video!");

(我意识到这是 C++,你正在使用 Python,但它应该是相似的)

(I realize this is C++ and you are working in Python but it should be similar)

更新:以上不适用于硬件加速视频播放.另一种可行的方法是创建一个图形场景并将视频小部件或播放器添加到场景中,并使用 QGraphicsTextItem 作为文本.将视口设置为 QGLWidget 将启用硬件加速:

Update: The above will not work for hardware accelerated video playback. An alternative that does work is to create a graphics scene and add the video widget or player to the scene and use a QGraphicsTextItem for the text. Setting the viewport to a QGLWidget will enable hardware acceleration:

QGraphicsScene *scene = new QGraphicsScene(this);

Phonon::VideoPlayer *v = new Phonon::VideoPlayer();
v->load(Phonon::MediaSource("video_file"));

QGraphicsProxyWidget *pvideoWidget = scene->addWidget(v);

QGraphicsView *view = new QGraphicsView(scene);
view->setViewport(new QGLWidget); //Enable hardware acceleration!

QGraphicsTextItem *label = new QGraphicsTextItem("Text Over Video!", pvideoWidget);
label->moveBy(100, 100);

v->play();

这篇关于python qt,在另一个小部件(声子)上方显示文本/标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆