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

Python 如何在PySide2中添加边框或设置透明QLayout?,python,qt,pyside2,Python,Qt,Pyside2,我正在为Blender做一个插件,我正在使用PySide2。我可以删除窗口标题,只显示窗口内容。我在QFrame中插入了一个动画gif,并更改了它的边框。问题是,容器仍然有尖锐的边缘出现 有没有办法更改QLayout样式? 我希望向QLayout添加角点,或者将其设置为透明而不是白色 这是我的密码: def __init__(self, parent=None): super(Ui_Form, self).__init__(parent) #size of the contai

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

有没有办法更改QLayout样式? 我希望向QLayout添加角点,或者将其设置为透明而不是白色

这是我的密码:

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

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

谢谢@eylllanesc。这真的很有效!又好又干净。