Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QlineEdit with constant text and editable text fields
Forum Updated to NodeBB v4.3 + New Features

QlineEdit with constant text and editable text fields

Scheduled Pinned Locked Moved Unsolved General and Desktop
widgetline editqt 5.4.2
13 Posts 5 Posters 8.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Embitel_qt
    wrote on last edited by
    #1

    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


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

    R 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      hi
      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?
      https://www.dropbox.com/s/cucmap61i8cyqdc/fixedtext.zip?dl=0

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Embitel_qt
        wrote on last edited by
        #3

        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.

        mrjjM 1 Reply Last reply
        0
        • E Embitel_qt

          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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Embitel_qt
          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.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Embitel_qt
            wrote on last edited by
            #5

            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.

            mrjjM 1 Reply Last reply
            0
            • E Embitel_qt

              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


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

              R Offline
              R Offline
              RobertoDuran
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • E Embitel_qt

                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.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Embitel_qt
                ah, so <X> can appear anywhere in the text
                and after insertion, should not be editable?
                So you need to support all cases of
                <X>aaaaa
                aaaa<X>aaaa
                aaaa<X>

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  To add to @mrjj do you mean something like Qt Creator's Default build directory settings in Build & Run -> General ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Embitel_qt
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • Hamed.MasafiH Offline
                      Hamed.MasafiH Offline
                      Hamed.Masafi
                      wrote on last edited by
                      #10
                      lineEdit->setInputMask("Im\\age\\_0000");
                      

                      Remote object sharing (OO RPC)
                      http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

                      Advanced, Powerful and easy to use ORM for Qt5
                      https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        Embitel_qt
                        wrote on last edited by
                        #11

                        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?

                        R 1 Reply Last reply
                        0
                        • E Embitel_qt

                          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?

                          R Offline
                          R Offline
                          RobertoDuran
                          wrote on last edited by
                          #12

                          @Embitel_qt Could you not just use 91 "x"s?

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

                          mrjjM 1 Reply Last reply
                          0
                          • R RobertoDuran

                            @Embitel_qt Could you not just use 91 "x"s?

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

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #13

                            might be slightly more compact to use the fill method. :)

                            http://doc.qt.io/qt-5/qstring.html#fill

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved