I am trying to create a demonstration app to show how to change font colors.
I can do it in QLabel and QTextEdit
I have found no way to change the foreground text color for a QLineEdit.
The only thing I've tried that does not throw an error is:
color = QColorDialog.getColor(defaultHost.textColor(), pWidget, 'Get Text Color')
myPalette.setColor(myPalette.WindowText, QColor(color))
But, the text color remains black...
Is it or is it not possible to do this?
In QC Designer, click on the QLineEdit box and in the properties, enable "autoFillBackground". Next, select the Palette property and in the pop up window, change the Text color to white.
You can do it by setting the object's style sheet:
self.my_line_edit = QtGui.QLineEdit()
self.my_line_edit.setStyleSheet("color: red;")
# or
self.my_line_edit.setStyleSheet("color: rgb(255, 0, 0);")
# or
self.my_line_edit.setStyleSheet("""
QLabel {
color: red;
}
""")
I solved for font text and background
self.my_line_edit.setStyleSheet(
"""QLineEdit { background-color: green; color: white }""")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With