How can I draw something on a VLC Video Widget?
I'm using VLC-Qt library to play video on a widget in my Qt application. My application requires drawing a text (or something like) on all videos. I already tried subclassing VlcWidgetVideo
and reimplementing paintEvent
. The method works when no video is playing. Though immadiately after starting to play, my paintings disappear. It looks like they are under VLC's video...
The code:
class TrackerWidgetVideo : public VlcWidgetVideo{
// Blah blah blah
protected:
void paintEvent(QPaintEvent *);
}
// .......
void TrackerWidgetVideo::paintEvent(QPaintEvent *e)
{
VlcWidgetVideo::paintEvent(e);
QPainter p(this);
p.drawText(rect(), Qt::AlignCenter, "Some foo goes here"); // This paints
}
Following images describe the situation better. First screenshot is when no video is playing. Second one is when I open a video file.
It looks like you want to create an overlay. If you take a look at
WidgetVideo.cpp
in the source for vlc-qt, you can see that therequest()
method creates a widget and adds it to a layout which is parented to theVlcVideoWidget
. This is probably messing with the overlay you're painting in yourpaintEvent
.To create an overlay that should stay on top of your video, follow the method outlined here: http://developer.nokia.com/community/wiki/How_to_overlay_QWidget_on_top_of_another
You should add an instance of the overlay class to your instance of
TrackerWidgetVideo
. The overlay class will contain the overridenpaintEvent
method that is currently part of yourTrackerWidgetVideo
. Then, you'll overrideTrackerWidgetVideo::resizeEvent
to resize your overlay class instance.Here's some example code:
Overlay.h
Overlay.cpp
TrackerWidgetVideo.h
TrackerWidgetVideo.cpp
Vlc creates two "internal" widgets on VlcVideoWidget when video is playing. Create a new widget as the VlcVideoWidget's sibling(not child), bring it to front and paint on it.