PDA

View Full Version : QLineEdit default text



Guilo
5th April 2010, 17:28
Hi !

I am using a QLineEdit and would like to have a default text when the QLineEdit is empty. Usually this text is grey and in italic (like in QtCreator). But the only thing I have found to perform this is setPlaceHolderText() but the documentation says it has been introduced in Qt 4.7...

Any idea ? Thanks

aamer4yu
5th April 2010, 17:45
You will need to subclas QLIneEdit.
On focusIn and focusOut events you will have set / clear the gray text.
And I guess making text gray is not that difficult :rolleyes:

Guilo
5th April 2010, 17:51
OK, I just wondered if there was something quicker

soulless
5th April 2010, 18:21
I think either you can use event filters: Events and Event Filters (http://qt.nokia.com/doc/4.6/eventsandfilters.html)

faldzip
5th April 2010, 23:22
You can check on qt.gitorious.com the sources and find how Trolls did it in Qt 4.7's QLineEdit :]

kongkong163
13th January 2011, 11:44
how did you solve your problem? I meet this too.