views:

102

answers:

1

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
Also note that since the label won't be in a layout, you'll need to manage its positioning manually.
Kaleb Pederson
Ok I putself.label = QtGui.QLabel("Hello, this is the subtitle", self.videoWidget)But it appears like a black box
Elias
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
I've updated my answer with an option that works. I tried it here but you lose hardware acceleration :(
Arnold Spence
Do you think it'll be possible to do what you're saying but to use it with opengl to access the ardwareacceleration?
Elias
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
hm ok, what do you think of displaying the text with opengl textures or freetype/bitmap fonts, do you think that will work?
Elias
It might. That's venturing past my direct experience :)
Arnold Spence
ok but thanks for all your help though!
Elias
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
amazing, gonna check it out!
Elias
I got it to work in python with your code! Thanks alot.
Elias