2014-03-03 33 views
0

我有QPushButton通過點擊來改變自己的圖標。如何使按鈕不要改變點擊背景

// in the slot 
btn->setIcon(expr ? icon1 : icon2); 

當用戶點擊並釋放按鈕時,如何禁用按鈕背景顏色的切換?

我只需要改變按鈕圖標。

回答

0

您可以使用樣式表與您想要的背景顏色,即

QPushButton{ background: red;} 
QPushButton:disabled{background: red;} 
QPushButton:pressed{background: red;} 
QPushButton:hover{background: red;} 

樣式的按鈕,你可以在你的項目的「設計」選項卡或代碼,即

btn->setStyleSheet("your style sheet string"); 
+0

感謝設置提示。我這樣解決了這個問題:btn-> setStyleSheet(「background-color:rgba(255,255,255,0%)」);我需要更仔細地研究風格的工作。 – kaa