class TestWidget(QWidget):
def __init__(self):
super(TestWidget, self).__init__()
self.resize(200, 200)
self.frame = QFrame()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
hl = QHBoxLayout()
hl.setContentsMargins(0, 0, 0, 0)
self.setLayout(hl)
hl.addWidget(self.frame)
with open("coner.qss", "r", encoding="utf-8") as f:
style = f.read()
self.setStyleSheet(style)
if __name__ == "__main__":
app = QApplication(sys.argv)
try:
widget = TestWidget()
widget.show()
except Exception as e:
print(e)
sys.exit(app.exec_())
coner.qss 文件内容如下:
QWidget{
background-color:lightgrey;
border:none;
border-radius:20px;
}