Home > database >  QTextEdit placeholder color
QTextEdit placeholder color

Time:03-11

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:

        name->setPlaceholderText("Name");
        author->setPlaceholderText("Author");
        description->setPlaceholderText("Description");

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

    QLineEdit[text=""],
    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.

CodePudding user response:

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.

https://doc.qt.io/qt-5/stylesheet-examples.html 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

https://forum.qt.io/topic/90176/change-qlineedit-placeholder-text-color

  • Related