我的代码如下:
primary1 = "#026C00"
secondary1 = "#2DBCE9"
class TemplatesIconLabel(qt.QLabel):
"""Label with a colored circular border.
The left half is blue and the right half is green.
"""
stylesheet = """
QLabel {
border-width: 10px;
border-style: solid;
border-radius: 25px;
border-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5,
stop:0 %s, stop:0.49 %s, stop:0.51 %s, stop:1 %s);
}
""" % (secondary1, secondary1, primary1, primary1)
def __init__(self, parent=None):
super().__init__(parent)
self.setStyleSheet(self.stylesheet)
self.setFixedSize(qt.QSize(51, 51))
结果很奇怪:
我尝试为左右边框设置常规颜色,并且仅对border-top-color
和border-bottom-color
使用渐变色,但这不能完全解决我的问题。