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?
+2
A:
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();
Arnold Spence
2010-09-11 22:53:44
Also note that since the label won't be in a layout, you'll need to manage its positioning manually.
Kaleb Pederson
2010-09-12 05:34:39
Ok I putself.label = QtGui.QLabel("Hello, this is the subtitle", self.videoWidget)But it appears like a black box
Elias
2010-09-12 09:15:52
This works for most ordinary widgets. I suppose being a video widget, there may be some hardware acceleration or overlay stuff going on that makes things a little trickier. I haven't used the phonon stuff, I'll take a look at the docs and suggest something else if I find anything.
Arnold Spence
2010-09-12 17:06:30
I've updated my answer with an option that works. I tried it here but you lose hardware acceleration :(
Arnold Spence
2010-09-12 19:46:43
Do you think it'll be possible to do what you're saying but to use it with opengl to access the ardwareacceleration?
Elias
2010-09-13 13:14:03
I tried that. After creating the graphics view you can add view->setViewport(new QGLWidget), and you get hardware acceleration back but the label becomes a black box again. Unless somebody knows a way to easily overlay a label with video, you may have to try something more involved with the video streams.
Arnold Spence
2010-09-13 16:56:21
hm ok, what do you think of displaying the text with opengl textures or freetype/bitmap fonts, do you think that will work?
Elias
2010-09-13 17:50:51
It might. That's venturing past my direct experience :)
Arnold Spence
2010-09-13 18:11:14
ok but thanks for all your help though!
Elias
2010-09-13 18:25:58
I got it working after all by using a QGraphicsTextItem instead of trying to add a QLabel to the scene. I'm updating my answer.
Arnold Spence
2010-09-13 21:23:32
amazing, gonna check it out!
Elias
2010-09-14 13:24:40
I got it to work in python with your code! Thanks alot.
Elias
2010-09-14 14:02:08