[英]How to get the background color of a button or label (QPushButton, QLabel) in PyQt
[英]PyQt QPushButton Background color
我有以下代碼:
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(0, 550, 150, 31))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
如何更改此按鈕的背景色。 我嘗試使用Palette,但沒有成功。 我希望顏色是紅色。 我似乎無法正確地稱呼它。 任何幫助都會很棒。
您可以更改按鈕的樣式:
self.pushButton.setStyleSheet("background-color: red")
就像CSS。
這是示例代碼。 您可以選擇任何樣式來設置背景顏色。
QPushButton button1, button2, button3;
button1.setStyleSheet("background-color: red");
button2.setStyleSheet("background-color:#ff0000;");
button3.setStyleSheet("background-color:rgb(255,0,0)");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.