Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

qlineedit

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:
http://i.imgur.com/dcXISZq.png

After I type something, the text goes away, replaced by the text entered:
http://i.imgur.com/wfmvUsx.png

like image 721
尺adioactiveςtud Avatar asked Apr 24 '14 17:04

尺adioactiveςtud


1 Answers

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

Ex:

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

enter image description here

like image 170
Tay2510 Avatar answered Oct 17 '22 01:10

Tay2510