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. add QLabel into QLineEdit
Forum Updated to NodeBB v4.3 + New Features

add QLabel into QLineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
32 Posts 5 Posters 16.7k Views 3 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Well , it will be messy as the cursor might go into/under label
    so not so easy to match up.
    The same you linked to is postfix so if we limit the length
    then it wont go into. but in ur case it will.

    M 1 Reply Last reply
    0
    • mrjjM mrjj

      Well , it will be messy as the cursor might go into/under label
      so not so easy to match up.
      The same you linked to is postfix so if we limit the length
      then it wont go into. but in ur case it will.

      M Offline
      M Offline
      marlenet15
      wrote on last edited by
      #7

      @mrjj is it even plausible to make the timestamp uneditable text and the rest can be editable. That way I don't add a QLabel inside the QLineEdit?

      mrjjM 1 Reply Last reply
      0
      • M marlenet15

        @mrjj is it even plausible to make the timestamp uneditable text and the rest can be editable. That way I don't add a QLabel inside the QLineEdit?

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

        @marlenet15
        well maybe u can make inputmask do something like that.

        Best solution would be custom widget but that is far more work.
        Not even sure how to make it overlap.

        M 1 Reply Last reply
        0
        • mrjjM mrjj

          @marlenet15
          well maybe u can make inputmask do something like that.

          Best solution would be custom widget but that is far more work.
          Not even sure how to make it overlap.

          M Offline
          M Offline
          marlenet15
          wrote on last edited by
          #9

          @mrjj Do you have an idea how to make it work with an input mask?

          mrjjM 1 Reply Last reply
          0
          • M marlenet15

            @mrjj Do you have an idea how to make it work with an input mask?

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

            @marlenet15
            yes using escape
            \D\A\T\E:AAAAA-AAAAA-AAAAA-AAAAA-AAAAA
            it shows as "Date:" and u cant change it.
            so should be able to show an actual date.

            M 1 Reply Last reply
            0
            • mrjjM mrjj

              @marlenet15
              yes using escape
              \D\A\T\E:AAAAA-AAAAA-AAAAA-AAAAA-AAAAA
              it shows as "Date:" and u cant change it.
              so should be able to show an actual date.

              M Offline
              M Offline
              marlenet15
              wrote on last edited by
              #11

              @mrjj So the actual text "Date:" can be changed to "Jan 19 2016" or any format of date?

              mrjjM 1 Reply Last reply
              0
              • M marlenet15

                @mrjj So the actual text "Date:" can be changed to "Jan 19 2016" or any format of date?

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

                @marlenet15
                yes
                its not pretty but
                \J\a\n\ \1\9\ \2\0\1\6:AAAAAA

                does look correct.

                raven-worxR M 2 Replies Last reply
                0
                • mrjjM mrjj

                  @marlenet15
                  yes
                  its not pretty but
                  \J\a\n\ \1\9\ \2\0\1\6:AAAAAA

                  does look correct.

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by raven-worx
                  #13

                  i also think the input mask is actually the best way, or maybe even better a custom QValidator.
                  But to just add something to the (rather ugly) QLabel idea: You could use QLineEdit::setTextMargins() to move the left-most position of the cursor.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  M 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @marlenet15
                    yes
                    its not pretty but
                    \J\a\n\ \1\9\ \2\0\1\6:AAAAAA

                    does look correct.

                    M Offline
                    M Offline
                    marlenet15
                    wrote on last edited by marlenet15
                    #14

                    @mrjj So right now in my code the date that is going into the QLineedit is the current date. So I would need to separate the string and make sure to add \ ? Also what do the A's mean? the ones you put in your example?

                    1 Reply Last reply
                    0
                    • raven-worxR raven-worx

                      i also think the input mask is actually the best way, or maybe even better a custom QValidator.
                      But to just add something to the (rather ugly) QLabel idea: You could use QLineEdit::setTextMargins() to move the left-most position of the cursor.

                      M Offline
                      M Offline
                      marlenet15
                      wrote on last edited by
                      #15

                      @raven-worx yes I agree the input mask Is the best way to go. However, it's a new concept for me since I never heard of it. That is why I am very confused to how it works.

                      mrjjM 1 Reply Last reply
                      0
                      • M marlenet15

                        @raven-worx yes I agree the input mask Is the best way to go. However, it's a new concept for me since I never heard of it. That is why I am very confused to how it works.

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

                        @raven-worx said:
                        setTextMargins
                        +1 That would work for custom control.

                        yes, you would need to put \ into your date.
                        the AAAA is input specifier .
                        Go to a LineEdit and find inputmask property and press F1 to read about them.

                        M 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @raven-worx said:
                          setTextMargins
                          +1 That would work for custom control.

                          yes, you would need to put \ into your date.
                          the AAAA is input specifier .
                          Go to a LineEdit and find inputmask property and press F1 to read about them.

                          M Offline
                          M Offline
                          marlenet15
                          wrote on last edited by marlenet15
                          #17

                          @mrjj So if the user is allowed 100 characters for the QLineEdit do I have to put 100 A's?

                          mrjjM raven-worxR 2 Replies Last reply
                          0
                          • M marlenet15

                            @mrjj So if the user is allowed 100 characters for the QLineEdit do I have to put 100 A's?

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

                            @marlenet15 erhm, yes I think. maybe there is way
                            but inputmasks are normally used for short input like date
                            or iP etc

                            1 Reply Last reply
                            0
                            • M marlenet15

                              @mrjj So if the user is allowed 100 characters for the QLineEdit do I have to put 100 A's?

                              raven-worxR Offline
                              raven-worxR Offline
                              raven-worx
                              Moderators
                              wrote on last edited by
                              #19

                              @marlenet15
                              if you are familiar with regular expressions you might want to use QRegExpValidator which will result in the same behavior
                              And set it on the line edit.

                              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                              If you have a question please use the forum so others can benefit from the solution in the future

                              mrjjM 1 Reply Last reply
                              1
                              • raven-worxR raven-worx

                                @marlenet15
                                if you are familiar with regular expressions you might want to use QRegExpValidator which will result in the same behavior
                                And set it on the line edit.

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

                                @raven-worx
                                oh. So QRegExpValidator can have static text?

                                raven-worxR 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @raven-worx
                                  oh. So QRegExpValidator can have static text?

                                  raven-worxR Offline
                                  raven-worxR Offline
                                  raven-worx
                                  Moderators
                                  wrote on last edited by
                                  #21

                                  @mrjj
                                  Of course, a regular expression can have a static text included

                                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                  If you have a question please use the forum so others can benefit from the solution in the future

                                  mrjjM M 2 Replies Last reply
                                  0
                                  • raven-worxR raven-worx

                                    @mrjj
                                    Of course, a regular expression can have a static text included

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

                                    @raven-worx
                                    yes, but i didn't know it would show in lineEdit as Validator sounds so none visual :)

                                    1 Reply Last reply
                                    0
                                    • raven-worxR raven-worx

                                      @mrjj
                                      Of course, a regular expression can have a static text included

                                      M Offline
                                      M Offline
                                      marlenet15
                                      wrote on last edited by
                                      #23

                                      @raven-worx Can you please show me an example of that? I have never heard of that and I googled it and I didn't find anything about that :)

                                      raven-worxR 1 Reply Last reply
                                      0
                                      • M marlenet15

                                        @raven-worx Can you please show me an example of that? I have never heard of that and I googled it and I didn't find anything about that :)

                                        raven-worxR Offline
                                        raven-worxR Offline
                                        raven-worx
                                        Moderators
                                        wrote on last edited by
                                        #24

                                        @marlenet15
                                        you can see how to use QRegExpValidator in the link i've posted.
                                        Use a RegExp similiar to this one. There are tons of material on the web about regexp to learn.

                                        QRegExp("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))");
                                        

                                        This regexp is surely not perfect, but enough to get an idea and continue to learn the syntax i guess.

                                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                        If you have a question please use the forum so others can benefit from the solution in the future

                                        kshegunovK M 2 Replies Last reply
                                        0
                                        • raven-worxR raven-worx

                                          @marlenet15
                                          you can see how to use QRegExpValidator in the link i've posted.
                                          Use a RegExp similiar to this one. There are tons of material on the web about regexp to learn.

                                          QRegExp("Comments\\: ([Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] [0-3]?[0-9] [0-9]{4}\\: (.+))");
                                          

                                          This regexp is surely not perfect, but enough to get an idea and continue to learn the syntax i guess.

                                          kshegunovK Offline
                                          kshegunovK Offline
                                          kshegunov
                                          Moderators
                                          wrote on last edited by
                                          #25

                                          @raven-worx
                                          If I may interject, [Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec] is not okay for matching one should use a (non-capturing) group instead. i.e: (?:Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Nov|Dec).

                                          Read and abide by the Qt Code of Conduct

                                          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