最近在项目要增加一个视频弹幕的功能,是打算在opengl显示的视频增加一个qt来显示,就需要qt界面透明,查找了一下在window上使用一下代码可以实现窗口透明子控件不透明。
this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setAutoFillBackground(false);
setWindowFlags(Qt::FramelessWindowHint);
但是移植到Ubuntu上显示是黑色的,查阅后qt文档
Platform notes:
X11: This feature relies on the use of an X server that supports ARGB visuals and a compositing window manager.
Windows: The widget needs to have the Qt::FramelessWindowHintwindow flag set for the translucency to work.
平台注意事项:
X11(linux):此特性依赖于能提供支持ARGB视觉效果和复合式视窗管理的X服务的功能开启。
Windows:此控件需要设置窗口标志Qt::FramelessWindowHint才能开启透明功能
猜测可能的原因是自带的桌面不支持窗口透明效果。网上查找了一下,有一位老哥给出了答案。
1、安装xcompmgr sudo apt-get install xcompmgr
2、设置xcompmgr自动启动
链接: link.