gpt4 book ai didi

python - 如何在 PySide2 中添加边框或设置 QLayout 透明?

转载 作者:行者123 更新时间:2023-12-01 06:40:06 25 4
gpt4 key购买 nike

我正在为 Blender 做一个插件,并且正在使用 PySide2。我能够删除窗口标题并仅显示窗口的内容。我在 QFrame 中插入了一个动画 gif 并更改了它的边框。问题是容器仍然出现尖锐的边框。

有什么方法可以改变QLayout样式吗?我希望向 QLayout 添加角或将其设置为透明而不是白色。

enter image description here

这是我的代码:

def __init__(self, parent=None):
super(Ui_Form, self).__init__(parent)
#size of the container of gif
self.size = QtCore.QSize(160, 100)
self.pixel = QtGui.QMovie(
'/home/mateus/Documents/Blender Projects/blender_pyside2_example-master/gui/img.gif')
self.pixel.setScaledSize(self.size)
#size of the window
self.setFixedSize(160, 100)
#style of with rounded corners
self.setStyleSheet("""
QFrame{
border-style: solid;
border-color: rgba(55, 55, 55, 255);
border-width: 3px;
border-radius: 10px;
background-color: rgba(55, 55, 55, 255);
}
""")

self.label = QtWidgets.QLabel()
self.label.setMovie(self.pixel)
self.pixel.start()
self.label.show()

layout = QtWidgets.QVBoxLayout()
layout.setMargin(0)
#attach gif to layout
layout.addWidget(self.label)

self.unsetCursor()

self.setLayout(layout)

最佳答案

您必须使窗口透明:

self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
self.setStyleSheet("""
QWidget{
background: transparent;
}
QFrame{
border-style: solid;
border-color: rgba(55, 55, 55, 255);
border-width: 3px;
border-radius: 30px;
background-color: rgba(55, 55, 55, 255);
}
""")

注意:布局不是图形元素,因此不能使其透明,必须使其透明的是容器。

关于python - 如何在 PySide2 中添加边框或设置 QLayout 透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59492972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com