Results 1 to 7 of 7

Thread: QlineEdit with constant text and editable text fields

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Location
    Bangalore
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default 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.LineEdit_Sample.png

    | 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.
    Make everything Simple yet Powerful

  2. #2
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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.

    Qt Code:
    1. QString stylesheet1 = QString("QLineEdit { background-color: white ; border: none ; }"); //alternatively you can set border-right : none for line edit 1 instead of border: none
    2. QString stylesheet2 = QString(" QLineEdit {background-color: white ; border: none ; }"); //alternatively you can set border-left : none for line edit 2
    3.  
    4. l_edit2->setText("Image_");
    5. l_edit2->setText("<COUNTER>");
    6. l_edit2->setReadOnly(true);
    7.  
    8. l_edit1->setStyleSheet(stylesheet1);
    9. l_edit2->setStyleSheet(stylesheet2);
    To copy to clipboard, switch view to plain text mode 
    Thanks :-)

  3. #3
    Join Date
    Nov 2011
    Location
    Bangalore
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default 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.
    Make everything Simple yet Powerful

  4. #4
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QlineEdit with constant text and editable text fields

    May you could explain your requirement, Insted of single usecase.
    Thanks :-)

  5. #5
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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

  6. #6
    Join Date
    Nov 2011
    Location
    Bangalore
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default 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.
    LineEdit_Sample2.png
    Make everything Simple yet Powerful

  7. #7
    Join Date
    Nov 2011
    Location
    Bangalore
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default 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

    Qt Code:
    1. lineEdit->setInputMask("xxxx\<\C\O\U\N\T\E\R\>");
    To copy to clipboard, switch view to plain text mode 

    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?
    Make everything Simple yet Powerful

Similar Threads

  1. Replies: 1
    Last Post: 11th March 2014, 12:20
  2. Contoured text in editable QGraphicsTextItem
    By stampede in forum Qt Programming
    Replies: 4
    Last Post: 9th November 2011, 00:22
  3. Qt Designer Different positions of text fields with same layout
    By Computer Hater in forum Qt Tools
    Replies: 2
    Last Post: 10th July 2011, 22:41
  4. Replies: 1
    Last Post: 30th November 2007, 11:03
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.