Paint over QVideoWidget
Symbian/Maemo phones, Qt 4.6.3.
I use QMediaPlayer for playing and QVideoWidget for displaying streaming video.
Now I'm trying to display some additional info over the video, for example video title, duration etc.
Is it somehow possible to put other widgets or paint on top of the QVideoWidget?
Since QVideoWidget inherits QWidget, you could just add another QWidget as its child, set position where you want and control opacity etc. The childWidget will appear on top of the video widget.
QWidget *childWidget = new QWidget(videoWidget);
I've tried this code:
QPushButton *btn = new QPushButton(videoWidget);
btn->setText("Button test" ) ;
But unfortunatelly button is still not displayed
[edit: fixed @ / chetankjain]
Ok, I need to build my Qt with Phonon support, but tried this quickly to check if this would work:
QPushButton *btn = new QPushButton(ui->label);
btn->setGeometry(5,5,20,20); // wrt the parent label
qDebug() << btn->geometry();
and it does ... but have to fix my env first and try this with QVideoWidget. I still think it should work... qDebug can chk if the geometry is right.
Have You tried sub-classing QVideoWidget and implementing a paintEvent like so:
void YourClass::paintEvent(QPaintEvent* e)
//... painting what you need over the content rendered by QVideoWidgets paintEvent
Try using top-level-widgets (no parent) as overlays.
That should work since those have own native window.
toplevelwidget dialog on N900 blurs the screen, video motion is not seen.
toplevelwidget PushButton is displayed below video, even though it should be on the top.
I've also tried to subclass QVideoWidget, but paintEvent method of new class is not called at all
during app running. This is strange, probably my mistake somewhere in the code.
I guess we'll have to wait till Qt 4.7 comes to Symbian,and hope it fixes the issue with video overlay.
I know it's an old thread (4 years), but others may find it through a search engine, like I did, trying to find a solution.
What worked for me was to do this:
Instead of using QVideoWidget, use a QGraphicsView:
Create a sub-class of QGraphicsView (say, MyGraphicsView)
Create a QGraphicsScene, adding to the graphics view (setScene)
Create a QGraphicsVideoItem and add it to your scene (addItem)
Set the player output to the graphics video created on step 3
Override paintEvent on your subclass and do your drawing
Here is some sample code:
@MyGraphicsView *view = new MyGraphicsView(this);
QGraphicsScene *scene = new QGraphicsScene(view);
QGraphicsVideoItem *item = new QGraphicsVideoItem();
Now, for the paintEvent:
@void MyGraphicsView::paintEvent(QPaintEvent *e)
// Do your drawing. // For e.g., draw a rectangle: painter.setPen(Qt::black); painter.drawRect(10, 10, 200, 200);