Qt - Flat QPushButton,背景颜色不起作用

tom*_*msk 7 qt flat qtstylesheets qpushbutton

QPushButton在Qt Designer中创建了这个样式表:

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;
 }
Run Code Online (Sandbox Code Playgroud)

它工作,但当我在属性中检查"平",然后它不再工作,我想问你为什么?我怎么能这样做,如果我需要平板QPushButton

Tho*_*dSO 14

对于问题的第二部分:不要使用"flat"属性,而是修改样式表以实现平面外观,可能是这样的:

QPushButton#pushButton { 
    background-color: #ffffff;
    border: 0px;
}
/* ... plus the rest of your stylesheet ... */
Run Code Online (Sandbox Code Playgroud)

关于"为什么不起作用"的一部分?根据我的经验,为小部件混合样式表和非样式表选项会产生许多难以解释的神秘效果.我放弃了要求"为什么"的.