Change only part of QLineEdit with input mask - possible?
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.
Re: Change only part of QLineEdit with input mask - possible?
Use escaped characters in the inputMask to display unchangable text. This, for example displays "TestXXX", where you can only edit the "XXX" part.
Code:
lineEdit->setInputMask("\\T\\e\\s\\tAAA");
lineEdit->setText("TestXXX");
Re: Change only part of QLineEdit with input mask - possible?
Wow, isn't that cool :)
Thank you!
Re: Change only part of QLineEdit with input mask - possible?
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? :)
Re: Change only part of QLineEdit with input mask - possible?
No, QLineEdit doesn't allow you to use rich text.
Re: Change only part of QLineEdit with input mask - possible?
Ok, just figured out that this particular feature is not strictly needed, so it can be dropped :)