0

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.

paddy
  • 60,864
  • 6
  • 61
  • 103
ejpszemo
  • 3
  • 2

1 Answers1

0

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

prosach
  • 312
  • 2
  • 14
  • Thanks, I'm gonna try method with catching empty signal! Still dissapointed that I can't just check if text is empty from qss, as in qlineedit. Have a good day! – ejpszemo Mar 08 '22 at 10:51