Reputation: 21
I want to change the color of the text next to a QCheckBox
.
I have tried these 2 questions:
how to change QCheckBox text label color in Qt?
None of those solutions seem to be working for me.
p = QtGui.QPalette(self.chkbox[i].palette())
p.setColor(QPalette.Active,QPalette.WindowText, QtCore.Qt.red)
self.top_grid.addWidget(self.chkbox[i],i+2,0)
Edit 1: Here is the minimal working code:
from PyQt4 import QtGui, QtCore
import sys
def main():
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
top_grid = QtGui.QGridLayout()
chkbox=[]
chkbox.append(QtGui.QCheckBox('1'))
chkbox[0].setStyleSheet("color: red")
chkbox[0].setToolTip('<b>ABC</b>' )
top_grid.addWidget(chkbox[0],0,0)
w.setLayout(top_grid)
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
When I do this, the color of the ToolTip
changes to red, but the text next to the checkbox remains black.
Edit 2: If I add the line
app.setStyle('cleanlooks')
It works. The default style is sgi
, where, for some reason, the text color doesn't change. It worked with all the other styles.
Upvotes: 2
Views: 7120
Reputation: 3945
You could do this by using style sheet:
for chbox in self.chkbox:
chbox.setStyleSheet("color: red")
Upvotes: 2