PDA

View Full Version : Change only part of QLineEdit with input mask - possible?



dpimka
9th July 2009, 15:34
Hello!

I have a line edit with an input mask with, say, 5 characters.

Question is this: can I somehow make QLineEdit to allow to change only last 3 chars in accordance to mask, and leave the first 2 untouched - as they were set by initial setText()?

To rephrase: I need an input mask to be set on part of the text, while not allowing to change another part.

I guess this is impossible, but who knows, Qt has many tricks ;)

TIA.

shentian
10th July 2009, 10:37
Use escaped characters in the inputMask to display unchangable text. This, for example displays "TestXXX", where you can only edit the "XXX" part.



lineEdit->setInputMask("\\T\\e\\s\\tAAA");
lineEdit->setText("TestXXX");

dpimka
10th July 2009, 10:57
Wow, isn't that cool :)
Thank you!

dpimka
10th July 2009, 11:01
Heh, now I have another question:

I need to paint part of the line edit's text in one color and other part in another color.
The only way I see is reimplementing paintEvent with all the drawing - frame, margins, text.

But maybe there's some quicker way? :)

wysota
10th July 2009, 11:59
No, QLineEdit doesn't allow you to use rich text.

dpimka
10th July 2009, 13:11
Ok, just figured out that this particular feature is not strictly needed, so it can be dropped :)