PDA

View Full Version : QLineEdit shadow text disappear on first entry



dentharg
5th July 2008, 12:27
Hi!

I am trying to achieve a "shadow text" in QLineEdit: ie. a text that is displayed within widget only until a user enters a first character (please see attachment). After that foreground color should change to default/black and "shadow text" should be replaced by contents given by user.

I've created a private slot "editTextChanged(QString)" in my QDialog-derived class that is connected to QLineEdit's textChanged() signal.

I've tried to use isModified() but when I get the notification to editTextChanged() the isModified is already true.

I cannot use setFocus() signal since this is the main widget of the window that gains focus immediately after showing the dialog.

What would be the best way to achieve such functionality?
Using QT4.4

Thank you!
-Marcin

jpn
6th July 2008, 17:40
In my opinion, focus in/out events would definitely be the best choices. Just like Opera's address bar and search box use them. As soon as they gains focus, the help text is hidden. As soon as they lose focus, the help text is shown again but only if nothing was entered, of course.