2016-01-07 56 views
3

我在Qt Designer創建QPushButton這個樣式表:的Qt - 平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; 
} 

它的作品,但是當我在屬性中查看「扁平化」,那麼它不」工作了,我想問你爲什麼?我該怎麼做,如果我需要平板QPushButton

+0

這是非常非常非常有用的!感謝分享 – KGCybeX

+0

@KGCybeX歡迎您:) – tomsk

回答

7

對於你的問題的第二部分:不要使用「扁平化」的屬性,但修改您的樣式表,實現了平面外觀,也許是這樣的:

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

關於「爲什麼不它的工作「的一部分?根據我的經驗,爲窗口小部件混合樣式表和非樣式表單選項會產生許多難以解釋的神祕效果。我放棄了要求「爲什麼」。

+0

謝謝,那工作:) – tomsk