John Smith
John Smith

Reputation: 861

How to change the text of a QLineEdit when the user click on the QLineEdit in Qt?

I have a QLineEdit with the text "Search contents...".

  1. I would like when QLineEdit has the focus or when the cursor go inside the text that the text is set to an empty string. [This works: I have no problem, I used the cursorPositionChanged signal of QLineEdit].

  2. I would like also when the QLineEdit leaves the focus and if the text is empty that the text of the QLineEdit is set to "Search contents...". [I don't know how to do that].

Upvotes: 1

Views: 514

Answers (1)

JSilver
JSilver

Reputation: 107

The placeholderText property of QLineEdit is exactly what you need.

Upvotes: 2

Related Questions