PDA

View Full Version : QlineEdit with constant text and editable text fields



arunpk
14th November 2015, 15:34
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.11516

| Image_<COUNTER> |
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.

prasad_N
14th November 2015, 16:39
You can use 2 line edits in horizontal layout.

Than set spacing 0 to the horizontal layout.
Then set style sheet as below.


QString stylesheet1 = QString("QLineEdit { background-color: white ; border: none ; }"); //alternatively you can set border-right : none for line edit 1 instead of border: none
QString stylesheet2 = QString(" QLineEdit {background-color: white ; border: none ; }"); //alternatively you can set border-left : none for line edit 2

l_edit2->setText("Image_");
l_edit2->setText("<COUNTER>");
l_edit2->setReadOnly(true);

l_edit1->setStyleSheet(stylesheet1);
l_edit2->setStyleSheet(stylesheet2);

arunpk
15th November 2015, 04:52
Thanks for the reply.

The content text of this LineEdit will be used as file name after replacing placeholder <COUNTER> with values from 0..N.

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 multiple LineEdits.

prasad_N
15th November 2015, 08:49
May you could explain your requirement, Insted of single usecase.

ars
15th November 2015, 10:13
Hello,

if youre use cases allow for a maximum length of the editable sections of the line edit content, you could try using line edit input mask. See http://doc.qt.io/qt-5.4/qlineedit.html#inputMask-prop

Best regards
ars

arunpk
16th November 2015, 05:45
Usecase1: mode = Cyclic
In this case by default there will be only <COUNTER> in LineEdit[automatically added] 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>[All entries in the pop up list cannot be used by the user[shows warning on selection]

Usecase2: mode = Limited
In this use case user can add any place holder[<CONTER>, <DATE>, <TIME>, etc...] from the pop up list and all this can be editable[no restrictions] and user can insert new characters anywhere in the LineEdit.
11522

arunpk
17th November 2015, 13:38
Thnaks for the inputs.
Now I have found a way to make my <COUNTER> non editable using the mask


lineEdit->setInputMask("xxxx\<\C\O\U\N\T\E\R\>");

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?