[SOLVED] QTextEdit placeholder color


here’s my problem:
I’m using Qt, I’ve got two QLineEdits (name, author) and one QTextEdit (description) in my form.
I need to set placeholders for each of them, so i wrote this code:


Now I want to style it using QSS, thus i wrote this:

    QTextEdit[text=""] {
      color: red;

But unfortunately this works only for QLineEdits and I cannot find a way to check if QTextEdit is empty in QSS.
Do you have any idea? Thanks in advance.


There is preety easy way of doing this programatically.
You can change the QPalette of your QLineEdit and QTextEdit and modify the QPalette::Text with setColor.

Another way of doing the same is catching signal if it is empty or not and setting stylesheet.

There is no reference of doing this in QT documentation.

If you want to look about complex examples other than this:

Change color of placeholder text in QLineEdit


Answered By – prosach

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *