Display QLabel above Phonon::VideoPlayer
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":
Code:
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.
Re: Display QLabel above Phonon::VideoPlayer
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.
Re: Display QLabel above Phonon::VideoPlayer
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
Code:
#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);
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();
titem->setPos(rect.width()/2, rect.height()/2);
#ifndef QT_NO_OPENGL
#endif
view.
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.show();
view.setWindowTitle("Eternal fire");
// view.showFullScreen();
return app.exec();
}
customproxy.h
Code:
#ifndef CUSTOMPROXY_H
#define CUSTOMPROXY_H
#include <QGraphicsProxyWidget>
class CustomProxy : public QGraphicsProxyWidget
{
Q_OBJECT
public:
CustomProxy
(QGraphicsItem *parent
= 0, Qt
::WindowFlags wFlags
= 0);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
private slots:
private:
};
#endif
customproxy.cpp
Code:
#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)