Flat QPushButton, background-color doesn't work

风格不统一 提交于 2019-11-29 19:48:19

问题


I created QPushButton in Qt Designer with this stylesheet:

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;
 }

It Works, but when i check "flat" in the properties, then it doesn't work anymore, I would like to ask you why? And how can i do it, if i need flat QPushButton ?


回答1:


For the second part of your question: Don't use the "flat" property, but modify your stylesheet to achieve a flat look, perhaps like this:

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

Concerning the "why doesn't it work" part? In my experience, mixing stylesheets and non-stylesheet-options for widgets yields many mysterious effects that are hard to explain. I have given up asking for the "why"s.



来源:https://stackoverflow.com/questions/34654545/flat-qpushbutton-background-color-doesnt-work

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