QlineEdit with constant text and editable text fields
I have a requirement to have a line edit which has a custom text which is non editable and another field where user can enter new text.
Please refer the attached image. custom line edit
In that image we can see that the "<COUNTER>" part should be non editable and should always be at the last position. And "Image_" is an editable text where user can enter any text.
Is there any way to have a custom LineEdit like this.
Its not an option just to use a QLabel and LineEdit together?
try this test and tell me if its not very close to what you want?
Thanks a lot for the example.
But this solution using QLabel & QLineEdit will not suit my usecase.
The content text of this LineEdit will be used as file name after replacing placeholder <COUNTER> with values from 0..N.
Hi can I ask what is wrong with it ?
Just to understand.
It would be easy to create function to return a QString containing
edit + Label text.
This above mentioned is only one use case. The actual functionality of my LineEdit will contain multiple placeholder fields like <DATE>, <TIME>, etc... which can be added to the LineEdit on the current cursor position.
So its not an option to use combination of QLineEdit & QLabel.
@Embitel_qt Will hiding the "<COUNTER>" piece of text in the code and having only a LineEdit be satisfactory? I mean storing QLineEdit as a string and adding <COUNTER> to it in code.
ah, so <X> can appear anywhere in the text
and after insertion, should not be editable?
So you need to support all cases of
To add to @mrjj do you mean something like Qt Creator's Default build directory settings in Build & Run -> General ?
@mrjj yes you are correct <X> can be added at any position in one usecase.
In my first use case [mode one] there will be only <COUNTER> and this should be always at the end of the LineEdit and which should not be edited. But the user can insert new characters before <COUNTER>
In my second use case[mode two] there can be any place holder[<CONTER>, <DATE>, <TIME>, etc...] all this can be editable[no restrictions] and user can insert new characters anywhere in the LineEdit.
Thnaks for the inputs.
Now I have found a way to make my <COUNTER> non editable using the mask
Now thw problem is I am able to enter only 4 characters before <COUNTER> but i want to allow the user to enter maximum of 91 charcters.
What should I modify on the reg expression to achieve this?
@Embitel_qt Could you not just use 91 "x"s?
might be slightly more compact to use the fill method. :)