PDA

View Full Version : Display QLabel above Phonon::VideoPlayer



kefir
9th March 2011, 17:41
Hi everybody! I have a little problem getting a QLabel (some text from a database) displayed above a video that is continuously played in Phonon::VideoPlayer widget. Both in windowed and fullscreen modes.

The "standard procedure":


QLabel *lbl = new QLabel(ui->videoPlayer); //same results with ui->videoPlayer->videoWidget() as parent
lbl->setText("test");


does not work very well. Neither does placing VideoPlayer inside a QGraphicsView.

So I'll be thankful if somebody could help solving this problem.

wysota
10th March 2011, 00:10
This won't work. Phonon rendering is done by an external engine so you can't put anything "on top" of it. You could try making the player and your label siblings (instead of parent and child) but you probably won't get a satisfactory result. I suggest you try with the new multimedia framework that comes with mobility 1.1. You shouldn't have problems there.

kefir
1st April 2011, 23:31
After trying lots and lots of variants...
Here's the acceptable solution. The code is crude but I think it can help those who have similar problems.

main.cpp


#include "customproxy.h"

#include <phonon/mediaobject.h>
#include <phonon/mediasource.h>
#include <phonon/videowidget.h>


#include <QtGui>
#include <QtDebug>
#include <QAbstractFileEngine>

#ifndef QT_NO_OPENGL
#include <QGLWidget>
#endif

int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(videowall);
QApplication app(argc, argv);

QGraphicsScene scene;

Phonon::MediaObject *media = new Phonon::MediaObject();
Phonon::VideoWidget *video = new Phonon::VideoWidget();
CustomProxy *proxy = new CustomProxy(0, 0);
Phonon::createPath(media, video);
proxy->setWidget(video);
QRectF rect = proxy->boundingRect();
proxy->setPos(0, 0);
proxy->show();
scene.addItem(proxy);

media->setCurrentSource(QString("output22.avi"));

media->play();

QGraphicsTextItem *titem = scene.addText("Bla-bla-bla");
titem->setPos(rect.width()/2, rect.height()/2);


QGraphicsView view(&scene);
#ifndef QT_NO_OPENGL
view.setViewport(new QGLWidget);
#endif
view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
view.setViewportUpdateMode(QGraphicsView::Bounding RectViewportUpdate);
view.show();
view.setWindowTitle("Eternal fire");
// view.showFullScreen();

return app.exec();
}


customproxy.h


#ifndef CUSTOMPROXY_H
#define CUSTOMPROXY_H

#include <QGraphicsProxyWidget>

class CustomProxy : public QGraphicsProxyWidget
{
Q_OBJECT
public:
CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);

QRectF boundingRect() const;


protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);

private slots:

private:

};

#endif


customproxy.cpp


#include "customproxy.h"

#include <QtGui>

CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsProxyWidget(parent, wFlags)
{
setCacheMode(NoCache);
}

QRectF CustomProxy::boundingRect() const
{
return QGraphicsProxyWidget::boundingRect().adjusted(0, 0, 0, 0);
}

void CustomProxy::resizeEvent(QGraphicsSceneResizeEvent *event)
{
//
}


Use wisely, live long and prosper =)

Special thanks to this article http://labs.qt.nokia.com/2008/11/28/videos-get-pimped/

Also I've tried combining ffmpeg + sdl but unfortunately got stuck with SDL_Surface not willing to attach itself to QWidget. But that's another story)