Qt 平面QPushButton,背景色不为';行不通

Qt 平面QPushButton,背景色不为';行不通,qt,qtstylesheets,qpushbutton,flat,Qt,Qtstylesheets,Qpushbutton,Flat,我使用以下样式表在Qt Designer中创建了QPushButton: QPushButton#pushButton { background-color: #ffffff; } QPushButton#pushButton:disabled { background-color: yellow; } QPushButton#pushButton:pressed { background-color: orange; } QPushButton#pushButto

我使用以下样式表在Qt Designer中创建了
QPushButton

QPushButton#pushButton { 
    background-color: #ffffff;
}
QPushButton#pushButton:disabled {
    background-color: yellow; 
}
QPushButton#pushButton:pressed {
    background-color: orange; 
}
QPushButton#pushButton:focus:pressed { 
    background-color: black;
 }
QPushButton#pushButton:focus { 
    background-color: green; 
}
QPushButton#pushButton:hover {
     background-color: red;
 }
QPushButton#pushButton:checked { 
    background-color: pink;
 }

它可以工作,但当我在属性中选中“flat”时,它就不再工作了,我想问你为什么?如果我需要平面
QPushButton
,我该怎么做呢?

对于问题的第二部分:不要使用“平面”属性,而是修改样式表以获得平面外观,可能如下所示:

QPushButton#pushButton { 
    background-color: #ffffff;
    border: 0px;
}
/* ... plus the rest of your stylesheet ... */

关于“为什么它不起作用”部分?根据我的经验,为小部件混合样式表和非样式表选项会产生许多难以解释的神秘效果。我已经不再问“为什么”了。

上面的这个非常非常有用!谢谢你sharing@KGCybeX欢迎:)