Important: Please read the Qt Code of Conduct -

How to change color of user text in QLineEdit

  • So I have a simple QLineEdit textbox that allows a user to login. The background color is dark grey so I wanted to make the user's text to be in white but I can't seem to figure out how to do this. In QtDesigner I have the option of changing font of text, but for some reason there's no option to change the text color. I've messed around with stylesheets but still can't get it.

    Any ideas?

  • Text color in pyqt is generally the foreground color try setting that and see if that works for you within the QLineEdit

  • Here the solution
    change colors if you like

            emailEdit.setStyleSheet("color: white;  background-color: black")

  • @DirkJ

    it is also possible to expand with selection color and selection background color

    emailEdit.setStyleSheet("color: blue; background-color: yellow; selection-color: yellow; selection-background-color: blue")

    rgb colors are possible too change color: in color: rgba(122,145,145)

  • 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.

  • Banned

    but do yourself a very big favor and do not use Qt Designer as that is not meant to produce quality code that is use-able in a project and in fact produces nothing but yuck that you cannot deal with since its supposed to be a black box which is always a bad thing in any code project

Log in to reply