PDA

View Full Version : How to embed label in lineedit?



blonde
1st December 2009, 07:13
How to embed label in lineedit?
or overlapping label above lineedit, so to look like the label is inside lineedit box?
see attached sceenshot

yogeshgokul
1st December 2009, 07:22
How to embed label in lineedit?
or overlapping label above lineedit, so to look like the label is inside lineedit box?

Create the label with line edit as parent and set the layout properly.

drhex
1st December 2009, 11:36
Put the text in the lineedit with setText(). Subclass the lineedit and capture keypresses so you can filter out the keypresses (cursor left, home, backspace) that would move the cursor into the forbidden area.

blonde
1st December 2009, 12:23
with yogeshgokul's solution, the LineEdit's cursor starts from the beginning,
the user inputs covers the label, label acts as a background.
How can you make the curor starts after the label?

yogeshgokul
1st December 2009, 12:45
with yogeshgokul's solution, the LineEdit's cursor starts from the beginning,the user inputs covers the label, label acts as a background.
How can you make the curor starts after the label?
Why dont you create your own widget? And design it how ever you want. Because in Qt any widget can be parent of any widget. So enjoy this freedom ;)

Lykurg
1st December 2009, 14:38
Why dont you create your own widget?
Because painting a QLineEdit with the blinking cursor is not as trivial as it seems for beginners... But after setting the label above the line edit just use QWidget::setContentsMargins() on the line edit (with the size of the label) and the label will stop to overlay the input text.

blonde
1st December 2009, 15:13
Because painting a QLineEdit with the blinking cursor is not as trivial as it seems for beginners... But after setting the label above the line edit just use QWidget::setContentsMargins() on the line edit (with the size of the label) and the label will stop to overlay the input text.

lineedit setContentsMargins() indents the lineedit box, it made the label out of the lineedit box.

Lykurg
1st December 2009, 15:26
Ups, I've ment: QLineEdit::setTextMargins().