Draw on top of xoverlay using qt



  • I wish to draw some UI on top of video stream that is rendered using Xoverlay. I am using gstreamer to play the video and render it on xvimagesink using xoverlay.
    My widget inherits from QGLWidget and I wish to draw 2D elements using QPainter
    I have done the following:

    @
    VideoPlayer::VideoPlayer(QWidget *parent) :
    QGLWidget(parent)
    {
    setAutoFillBackground(false);
    QString fname = QFileDialog::getOpenFileName(0,tr("Open video"),tr("/"));
    GstElement *pipeline,*source,*decoder,*q,*converter,*resampler,*audiosink,*videosink;
    GstBus *bus;
    pipeline = gst_pipeline_new("my-player");
    source = gst_element_factory_make("filesrc","source");
    decoder = gst_element_factory_make("decodebin2","decoder");
    q = gst_element_factory_make("queue","q");
    converter = gst_element_factory_make("audioconvert","converter");
    resampler = gst_element_factory_make("audioresample","resampler");
    audiosink = gst_element_factory_make("autoaudiosink","audio-sink");

    videosink = gst_element_factory_make("xvimagesink","video-sink");
    
    //Set the bin properties
    g_object_set(G_OBJECT(source),"location",fname.toAscii().constData(),NULL);
    g_object_set(G_OBJECT(decoder),"name","decoder");
    
     gst_bin_add_many(GST_BIN(pipeline),source,decoder,q,converter,resampler,audiosink,videosink,NULL);
    gst_element_link(source,decoder);
    gst_element_link_many(q,converter,resampler,audiosink,NULL);
    //gst_element_link(decoder,q);
    g_signal_connect(decoder,"pad-added",G_CALLBACK(on_pad_added),videosink);
    g_signal_connect(decoder,"pad-added",G_CALLBACK(on_pad_added),q);
    
    
    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_add_watch(bus,bus_call,NULL);
    gst_object_unref(bus);
    
    
    if (GST_IS_X_OVERLAY (videosink))
       {
           unsigned long win_id=winId();
           QApplication::syncX();
           gst_x_overlay_set_xwindow_id (GST_X_OVERLAY(videosink),win_id);
       }
    
    
    gst_element_set_state(pipeline,GST_STATE_PLAYING);
    }
    

    @

    Then I reimplement paintEvent as follows
    @
    void VideoPlayer::paintEvent(QPaintEvent *event) {
    QPainter painter(this);
    painter.save();
    painter.setPen(QColor(255,0,0,140));
    painter.drawRect(QRectF(50,50,100,100));
    painter.restore();

    }
    

    @

    The problem is that the rectangle gets painted below the video..
    How do i overpaint it so that it shows above the video???
    Please help..
    thanks...



  • Please... any help would be highly appreciated!!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.