PDA

View Full Version : QLineEdit and background text



SnarlCat
6th March 2009, 18:24
All-

I've got a QLineEdit that is used to specify a file path for either Windows or Unix environments. I've got a QRegExpValidator to ensure things are entered correctly, but to a new user, the format it accepts may be non-obvious -- when they start typing and nothing happens, it'd be rather confusing.

I'd like to write, in the text-entry space, a brief statement of what format the QLineEdit is accepting, eg "Insert Windows filename here", but not as the value of QLineEdit (e.g., not via setText(..)).

My thoughts were to use a QPainter and drawText into this space when the text() was empty (and the widget is enabled) in a light-colored font (as to not confuse, but rather inform, the user). This text would be more obvious than a tooltip.

I've tried to re-implement paintEvent directly and use QCoreApplication::sendEvent() with a QPaintEvent object that defines the rect() of the QLineEdit to no avail.

Can anyone provide some hints as to how to get this working, or suggest an alternative technique?

Thanks!

SnarlCat

jpn
6th March 2009, 18:41
I've tried to re-implement paintEvent directly and use QCoreApplication::sendEvent() with a QPaintEvent object that defines the rect() of the QLineEdit to no avail.
Hmm, what was the problem with paintEvent()? It should work... I don't understand what is QCoreApplication::sendEvent() needed for, though.

SnarlCat
6th March 2009, 22:17
*grumble*

Chalk this one up to RTFM(better)..

Sorry for the noise..

SnarlCat