Styling with classes in Pyside + Python

为君一笑 提交于 2019-12-03 16:34:46

If I am not mistaken, stylesheets of a parent are applied to all children unless overwritten.

You can try this:

    # STYLING
    self.setStyleSheet("QLabel { color: rgb(50, 50, 50); font-size: 11px; background-color: rgba(188, 188, 188, 50); border: 1px solid rgba(188, 188, 188, 250); } QSpinBox { color: rgb(50, 50, 50); font-size: 11px; background-color: rgba(255, 188, 20, 50); }")

    #setting CS of self (the widget) and not the children

    self.setGeometry(800, 400, 250, 80)
    self.setWindowTitle('Simple Calculator')
    self.show()

Concerning your different buttons:

label1.setProperty('labelClass', 'red')
label2.setProperty('labelClass', 'blue')

and in the CS of the widget:

QLabel[labelClass="red"] {...}
QLabel[labelClass="blue"] {...}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!