python - 不透明时显示一次后无法设置 QWindow 的透明度
问题描述
我有一个窗口在不透明的情况下显示一次后试图使其透明。但是,即使我再次隐藏和显示也不会透明。这就是我得到的:
但我想要这样:(背景透明)
如果我WA_TranslucentBackground
先运行,在 .show()
它按预期创建一个漂亮的透明按钮之前。
这是一个示例代码,当您运行它时会显示一个浮动按钮
import sys
from PySide2 import QtCore, QtWidgets, QtGui
class TransparentWindow(QtWidgets.QMainWindow):
def __init__(self):
super(TransparentWindow, self).__init__()
self.setCentralWidget(QtWidgets.QWidget(self))
self.mainLayout = QtWidgets.QVBoxLayout()
self.centralWidget().setLayout(self.mainLayout)
self.mainLayout.addWidget(QtWidgets.QPushButton("Hello World", parent=self))
self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
self.show() # If I move this under '.setAttribute()' it works
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
demo = TransparentWindow()
sys.exit(app.exec_())
我试过隐藏和重新显示“setAutoFillBackground()”和“WA_NoSystemBackground”属性,但我似乎无法让它工作。有人知道如何在显示为不透明后设置透明度吗?
使用版本 QtCore:5.9.6,Pyside2:5.9.0a1.dev1528389443
解决方案
推荐阅读
- jquery - JQuery toggleClass 不适用于动态数据
- android - 我可以选择未附加到布局的微调器项目吗?它在 Spinner.MODE_DIALOG
- python - 比较具有熊猫字符串列表的两列
- javafx - JavaFX 任务 updateValue 抛出 IllegalStateException:不在 FX 应用程序线程上
- csv - 读取缺少列和随机列顺序的 csv 文件
- ruby-on-rails - Rails/Ruby:将查询结果转换为多级哈希
- c# - DocumentDB 显示特定实体类型的所有文档
- typescript - '"combined"' 类型的参数不能分配给 'FormatFn' 类型的参数
- php - PHP 时差
- javascript - 图层上的mapbox gl js单击事件