1 Attachment(s)
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.Attachment 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.
Re: QlineEdit with constant text and editable text fields
You can use 2 line edits in horizontal layout.
Than set spacing 0 to the horizontal layout.
Then set style sheet as below.
Code:
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);
Re: QlineEdit with constant text and editable text fields
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.
Re: QlineEdit with constant text and editable text fields
May you could explain your requirement, Insted of single usecase.
Re: QlineEdit with constant text and editable text fields
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
1 Attachment(s)
Re: QlineEdit with constant text and editable text fields
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.
Attachment 11522
Re: QlineEdit with constant text and editable text fields
Thnaks for the inputs.
Now I have found a way to make my <COUNTER> non editable using the mask
Code:
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?