I have a LineEdit widget in an app and its PlaceholderText changes based on the user's input. However, I'd like for the PlaceholderText to look like normal text, i.e. to be black instead of grey.
I've looked online but most of the results were either not precise enough for me to understand them or using different languages than Python, which makes it hard for me to implement the solution in my script.
To change the color of the placeholderText then you have to use the QPalette:
import sys
from PyQt5 import QtGui, QtWidgets
def main():
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QLineEdit(placeholderText="Stack Overflow")
pal = w.palette()
text_color = pal.color(QtGui.QPalette.Text)
# or
# text_color = QtGui.QColor("black")
pal.setColor(QtGui.QPalette.PlaceholderText, text_color)
w.setPalette(pal)
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
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