Python中文
首页
教程
问答
标签
搜索
登录
注册
Qt5中子窗口小部件的透明度
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我在Linux for Tegra(Ubuntu18,X11窗口系统)、Python3.6和PyQt5上使用Nvidia Jetson Nano。我想在主窗口小部件上放置一个透明窗口小部件(或具有透明背景)</p> <p>当这些小部件作为独立部件创建时,所有内容都会正确显示。即使gstreamer视频流显示在主窗口小部件中,透明度也可以工作</p> <pre><code>import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class MainWindow(QWidget): def __init__(self): QWidget.__init__(self) self.setGeometry(50,50,320,240) self.setWindowTitle("Main Window") self.setStyleSheet("background-color:yellow;") self.label = QLabel(self) self.label.setText("Main Widget") self.menu = MenuWidget() class MenuWidget(QWidget): def __init__(self): QWidget.__init__(self) self.setWindowFlags(Qt.Tool) self.setGeometry(100,100,100,50) self.setWindowFlags(Qt.FramelessWindowHint) self.setStyleSheet("background-color:gray;") self.setWindowOpacity(0.5) self.label = QLabel(self) self.label.setText("Menu Widget") app = QApplication([]) window = MainWindow() window.show() window.menu.show() sys.exit(app.exec_()) </code></pre> <p>[<img src="https://i.stack.imgur.com/ViQVb.jpg" alt="enter image description here"/> <a href="https://i.stack.imgur.com/1yeM0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1yeM0.jpg" alt="enter image description here"/></a></p> <p>当我尝试创建一个小部件作为主小部件的子部件时,透明度不起作用。如果显示视频,则主小部件窗口中会出现一个“洞”</p> <pre><code>class MainWindow(QWidget): def __init__(self): QWidget.__init__(self) self.setGeometry(50,50,320,240) self.setWindowTitle("Main Window") self.setStyleSheet("background-color:yellow;") self.label = QLabel(self) self.label.setText("Main Widget") self.menu = MenuWidget(parent=self) print('main window created') class MenuWidget(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) self.setWindowFlags(Qt.Tool) self.setGeometry(100,100,100,50) self.setWindowFlags(Qt.FramelessWindowHint) self.setStyleSheet("background-color:gray;") self.setWindowOpacity(0.5) self.label = QLabel(self) self.label.setText("Menu Widget") app = QApplication([]) window = MainWindow() window.show() sys.exit(app.exec_()) </code></pre> <p><a href="https://i.stack.imgur.com/JzWF0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JzWF0.jpg" alt="enter image description here"/></a> <a href="https://i.stack.imgur.com/TWEcg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TWEcg.jpg" alt="enter image description here"/></a></p> <p>另外,如果我为子窗口小部件设置属性self.setAttribute(Qt.WA_TranslucentBackground),主窗口中会出现一个“洞”(如果在此窗口中播放视频)</p> <p><a href="https://i.stack.imgur.com/anWzt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/anWzt.jpg" alt="enter image description here"/></a></p> <p>如何为儿童小部件设置透明度?提前感谢您的回答</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>据我所知,小部件的透明度(背景透明度)只能使用桌面合成器创建。Qt无法使用桌面合成器呈现子窗口小部件。唯一的解决方案是使用独立的窗口/小部件。唯一的解决方案是使用独立的窗口/小部件</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
VirtualEnvRapper错误:路径python2(来自python=python2)不存在
5 回答
virtualenvs上的pyinstaller,没有名为导入错误的模块
5 回答
virtualenvs是否可以退回到用户包而不是系统包?
9 回答
virtualenvwrapper CentOS7
10 回答
virtualenvwrapper IOError:[Errno 13]权限被拒绝
3 回答
virtualenvwrapper mkproject和shell在windows中的启动问题?
5 回答
virtualenvwrapper mkvirtualenv不工作但没有错误
10 回答
Virtualenvwrapper python bash
4 回答
virtualenvwrapper:“workon”何时更改到项目目录?
3 回答
virtualenvwrapper:mkvirtualenv可以工作,但是rmvirtualenv返回bash:没有这样的文件或目录
10 回答
virtualenvwrapper:virtualenv信息存储在哪里?
4 回答
virtualenvwrapper:命令“python设置.pyegg_info“失败,错误代码为1
5 回答
virtualenvwrapper:如何将mkvirtualenv的默认Python版本/路径更改为ins
7 回答
Virtualenvwrapper:模块“pkg_resources”没有属性“iter_entry_points”
4 回答
Virtualenvwrapper:没有名为virtualenvwrapp的模块
3 回答
Virtualenvwrapper.bash_profi的正确设置
2 回答
Virtualenvwrapper.hook:权限被拒绝
1 回答
virtualenvwrapper.sh:fork:资源暂时不可用Python/Djang
6 回答
Virtualenvwrapper.shlssitepackages命令不工作
2 回答
Virtualenvwrapper.sh函数在bash sh中不可用
7 回答