gkzscs: 需要先在自定义控件类里,用`Q_PROPERTY`声明属性,为属性设置不同的值,并在`qss`中为属性的每个值添加相应的样式。 [code=cpp] class OptionalButton : public QLabel { Q_OBJECT Q_PROPERTY(bool selected READ selected WRITE setSelected) Q_PROPERTY(bool pressed READ pressed WRITE setPressed) }; [/code] [code=css] OptionalButton[pressed="true"] { background-color: rgba(15, 255, 255, 0.5); } OptionalButton[selected="true"] { background-color: rgba(15, 255, 255, 0.2); } [/code]
ubuntu 23开机界面美化教程
关于Qt中setStyleSheet()易踩的坑——样式覆盖