python qt, display text/label above another widget(phonon)

强颜欢笑 提交于 2019-12-18 18:38:40

问题


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?


回答1:


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!");

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

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();


来源:https://stackoverflow.com/questions/3692712/python-qt-display-text-label-above-another-widgetphonon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!