QDeclarativeView transparency containing QML on top of a QWidget that plays video (using either phonon or libvlc)

I am currently developing a video player.

The GUI as the topmost layer is written in QML. It should be transparent to the lower layers. It contains controls, some lists, etc. It is displayed using QDeclarativeView .

Description

  QDeclarativeView *upperLayer = new QDeclarativeView(this); upperLayer->setSource(QUrl("/home/projects/QtVideo/qml/videoControl.qml")); upperLayer->setStyleSheet(QString("background: transparent"); upperLayer->setResizeMode(QDeclarativeView::SizeRootObjectToView); uperLayer->showFullScreen(); 

Layer under QWidget: I use libvlc to display video content in this widget.

Reason: I get MPEG-TS, which cannot be decoded by phonon, afaik. Therefore, I need libvlc to decode the incoming *.ts and display the output.

 QWidget *lowerLayer = new QWidget(this); lowerLayer.setGeometry(QString("background: red")); QUrl* url = new QUrl("file:///home/projects/QtVideo/video.ts"); libvlc_instance_t*vlcObject; libvlc_media_t*vlcMedia; libvlc_media_player_t*vlcPlayer; vlcPlayer = NULL; if(vlcObject = libvlc_new(argc, argv)) == NULL) { printf("Not able to initialize"; exit(1); } if(vlcPlayer && libvlc_media_player_is_playing(vlcPlayer)) { libvlc_media_player_stop(vlcPlayer); } vlcPlayer = libvlc_media_player_new(vlcObject); vlcMedia = libvlc_media_new_location(vlcObject, url.toString().toUtf8().constData()); libvlc_media_player_set_media(vlcPlayer, vlcMedia); #if defined(Q_OS_MAC) libvlc_media_player_set_nsobject(vlcPlayer, lowerLayer->winId()); #elif defined(Q_OS_UNIX) libvlc_media_player_set_x_window(vlcPlayer, lowerLayer->winId()); #elif defined(Q_OS_WIN) libvlc_media_player_set_hwnd(vlcPlayer, lowerLayer->winId()); #endif libvlc_media_player_play(vlc_player); 

Both elements, QDeclarativeView and QWidget are embedded in QMainWindow , the lower layer created before upperLayer , upperLayer Transparent for lowerLayer .

Problem:

As long as the bottom layer displays static elements, such as an image or some colored shapes, everything works fine, completely transparent and functional.

As soon as I start showing a video, for example, described *.ts using libvlc OR some random video using Phonon::VideoPlayer , the parts of the upperLayer that are above the lowerLayer video lowerLayer displayed in the color lowerLayer(default: gray) , parts of the correct behavior of the upperLayer that are located above parts of lowerLayer or others that do not contain video elements are displayed correctly.

Question:

Is there any possibility and if, how, to get a transparent top layer, even if there is a video game?

+4
source share
2 answers

Are you still struggling with this problem? Unfortunately, I do not have a satisfactory answer for you. The best I can do is point out the reasons why this is not working:

http://lists.trolltech.com/qt-interest/2007-02/thread01061-0.html

See message # 4 in the link above.

I tried many different methods to get transparent painting over the video (in particular, Phonon :: VideoPlayer) using Qt. The only method I've found so far is to set the overlay QWidget as toolTip, doing something like

 pWidget->setWindowFlags(Qt::ToolTip) 

Depending on what exactly you want to do this, it may be enough, but (in my opinion) it is a hack at best. I am actively struggling with this problem, and if I can find some solution, I will definitely post it here.

Good luck.

+3
source

you are using direct rendering (by passing the widget to the widget), which draws a video add-in in this geometry:

 libvlc_media_player_set_x_window 

you need to use the rendering on the screen and draw it on your qwidget. this can be done with the opengl context (complex) or using the callback methods available in libvlc.

if you use the display callback (libvlc_video_display_cb), libvlc will also generate lock / unlock methods if you need to. in this method, libvlc expects some parameters to be set, such as canvas geometry and pixel format.

which said phonon has a libvlc server that can help but can still use direct rendering depending on some factors.

+2
source

All Articles