在播放视频的QWidget之上包含QML的QDeclarativeView的透明度(使用phonon或libvlc) [英] Transparency of QDeclarativeView containing QML on top of a QWidget playing a video (using either phonon or libvlc)

查看:316
本文介绍了在播放视频的QWidget之上包含QML的QDeclarativeView的透明度(使用phonon或libvlc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发视频播放器.

I am currently developing a video player.

GUI作为最顶层使用QML编写.它对下层应该是透明的.它包含控制元素,一些列表等,使用QDeclarativeView显示.

The GUI as the topmost layer is written in QML. It should be transparent to lower layers. It contains control elements, some Lists etc., It's displayed using a QDeclarativeView.

 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();

下面的层是一个QWidget:我使用libvlc显示视频内容 在此小部件中.

The layer underneath is a QWidget: I use the libvlc to display the video content in this widget.

原因:我正在接收MPEG-TS,声子afaik无法对其进行解码.因此,我需要libvlc来解码传入的*.ts流并将输出放到显示器上.

Reason: I am receiving MPEG-TS, which can not be decoded by phonon, afaik. Therefore I need the libvlc to decode the incoming *.ts stream and put the output onto the display.

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);

两个元素,QDeclarativeViewQWidget 嵌入在QMainWindow中,在upperLayer之前创建的lowerLayer中, upperLayerlowerLayer透明.

Both Elements, the QDeclarativeView and the QWidget are embedded in a QMainWindow, lowerLayer created before the upperLayer, upperLayer Transparent to the lowerLayer.

只要lowerLayer显示静态元素(例如图片或某些彩色形状),一切都将正常工作,具有完全的透明度和功能.

As long as the lowerLayer is displaying static elements such as a picture, or some colored shapes, everything works fine, full transparency and functionality.

我一开始显示视频,例如使用libvlc所述的*.ts或使用Phonon::VideoPlayer的一些随机视频,则upperLayer的部分在lowerLayer的视频部分之上以lowerLayer(default: gray)的颜色显示,位于lowerLayer部分上方的upperLayer部分或不包含视频元素的其他部分以正确的方式显示.

As soon as I start displaying a video, such as the described *.ts using the libvlc OR some random video using the Phonon::VideoPlayer, the parts of the upperLayer which are above the video parts of the lowerLayer are displayed in the color of the lowerLayer(default: gray), the parts of the upperLayer which are positioned above parts of the lowerLayer or others which do not contain video elements are displayed in correct behaviour.

即使正在播放视频,是否存在任何可能性,以及如何使upperLayer透明?

Is there any posibility and if, how, to get the upperLayer transparent, even if there is a video playing?

推荐答案

您还在为这个问题而战吗?可悲的是,我没有一个令人满意的答案.我能做的最好的事情就是为您指出无法正常工作的原因:

Are you still fighting with this issue? I, sadly, do not have a satisfying answer for you. The best I can do is point you to reasons why it doesn't work:

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

请参阅上面链接中的消息4.

See Message #4 in the link above.

我尝试了许多不同的方法来使用Qt在视频(特别是Phonon :: VideoPlayer)上进行透明绘画.到目前为止,我发现的唯一方法是将覆盖的QWidget设置为toolTip来完成

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

pWidget->setWindowFlags(Qt::ToolTip)

取决于您确切要执行的操作可能就足够了,但是(在我看来)这充其量是hack.我正在为这个问题而苦苦挣扎,如果我能找到某种解决方法,我一定会在这里发布.

Depending on what exactly you're wanting to do this may be sufficient, but (in my opinion) it's a hack at best. I'm actively struggling with this issue and if I can find some sort of solution, I'll be sure to post it here.

祝你好运.

这篇关于在播放视频的QWidget之上包含QML的QDeclarativeView的透明度(使用phonon或libvlc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆