Qt (C++): Add background text in line edit
Asked Answered
D

1

9

I want to be able to add a line of (grey) text that when you type in the line edit, goes away. So the text is not actually there, it is just displayed.

For example:
Before I type something, the grey background text is there:
https://i.sstatic.net/2U955.png

After I type something, the text goes away, replaced by the text entered:
https://i.sstatic.net/JXVAQ.png

Diabolize answered 24/4, 2014 at 17:19 Comment(0)
S
10

void QLineEdit::setPlaceholderText( const QString & ) is what you are looking for:

Ex:

ui->lineEdit->setPlaceholderText(QString("Type here"));

enter image description here

Sholes answered 24/4, 2014 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.