I'm using Qt and Gstreamer to create a video viewer. I'm using this simple code to show a video:
GstElement* MainWindow::addVideo(QWidget* parent, const int& x, const int& y, const int& width, const int& height) {
GstElement* pipeline = gst_pipeline_new ("xvoverlay");
GstElement* src = VideoView::makeElement("v4l2src", { {"device", "/dev/video0"} });
GstElement* queue = gst_element_factory_make ("videoconvert", nullptr);
GstElement* sink = gst_element_factory_make ("xvimagesink", nullptr);
if (sink == nullptr)
g_error ("Couldn't find a working video sink.");
gst_bin_add_many (GST_BIN (pipeline), src, queue, sink, nullptr);
gst_element_link_many (src, queue, sink, nullptr);
QWidget* videoView = new VidView();
videoView->setParent(parent);
videoView->move(x, y);
videoView->resize(width, height);
videoView->setStyleSheet("background-color: red");
videoView->show();
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (sink), videoView->winId());
gst_element_set_state (pipeline, GST_STATE_PLAYING);
GstStateChangeReturn sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (sret == GST_STATE_CHANGE_FAILURE) {
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
// Exit application
QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
}
return pipeline;
}
It work well. But now I need to display some semi-transparent widgets above the video (for instance to have a title bar showing the name of the camera, or a popup above all the window). Here's what I get when showing a semi-transparent yellow QWidget partially overlaying the video:
As you can see, under the yellow widget the video view background is shown, not the video.
Here's the code used to create that second widget:
QWidget* test = new QWidget(m_mainContainer);
test->resize(100, 100);
test->move(150, 150);
test->setStyleSheet("background-color: #55ffff00;");
How can I fix this?
Note: I can't use the glimagesink, because it has performances problems when showing multiple videos (the app will be showing up to 8 4K videos).