Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Elide text in TextField

Elide text in TextField

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 3.9k Views
  • 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.
  • A Offline
    A Offline
    AYYAPPA
    wrote on 26 Jun 2018, 08:47 last edited by
    #1

    hello,

    i want to know how to elide text in TextField when textField focus change to false.(not entering values in textfield).

    thanks,
    ayyappa.

    R 1 Reply Last reply 26 Jun 2018, 08:58
    0
    • A AYYAPPA
      26 Jun 2018, 08:47

      hello,

      i want to know how to elide text in TextField when textField focus change to false.(not entering values in textfield).

      thanks,
      ayyappa.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 26 Jun 2018, 08:58 last edited by
      #2

      @AYYAPPA
      something like this:

      TextField {
          id: textField
          property string fullText: .... // set your actual text content here
          text: activeFocus ? fullText : metrics.elidedText
       
          TextMetrics {
              id: metrics
              font: textField.font
              text: textField.fullText
              elideWidth: textField.width - 5
          }
      }
      

      (untested)

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

      K 1 Reply Last reply 22 Aug 2023, 00:55
      0
      • A Offline
        A Offline
        AYYAPPA
        wrote on 26 Jun 2018, 10:25 last edited by
        #3

        @raven-worx sounds good. i will try and let you know . thanks !!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AYYAPPA
          wrote on 27 Jun 2018, 07:27 last edited by
          #4

          i still feel it would have been better if TextFiled has the ability to store full text and show elided text like Text item.
          is there any other qml item which does same job as TextField and has elides text when gone beyond width ??
          if you see login page of Instagram , user name filed uses TextField kind of item but does the eliding operation by itself !!

          R 1 Reply Last reply 27 Jun 2018, 08:36
          0
          • A AYYAPPA
            27 Jun 2018, 07:27

            i still feel it would have been better if TextFiled has the ability to store full text and show elided text like Text item.
            is there any other qml item which does same job as TextField and has elides text when gone beyond width ??
            if you see login page of Instagram , user name filed uses TextField kind of item but does the eliding operation by itself !!

            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 27 Jun 2018, 08:36 last edited by
            #5

            @AYYAPPA
            i am not aware of any (input-)control in Qt which has eliding support

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AYYAPPA
              wrote on 27 Jun 2018, 08:59 last edited by
              #6

              ok thank you

              1 Reply Last reply
              0
              • R raven-worx
                26 Jun 2018, 08:58

                @AYYAPPA
                something like this:

                TextField {
                    id: textField
                    property string fullText: .... // set your actual text content here
                    text: activeFocus ? fullText : metrics.elidedText
                 
                    TextMetrics {
                        id: metrics
                        font: textField.font
                        text: textField.fullText
                        elideWidth: textField.width - 5
                    }
                }
                

                (untested)

                K Offline
                K Offline
                Kamichanw
                wrote on 22 Aug 2023, 00:55 last edited by Kamichanw
                #7

                @raven-worx This seems cannot work properly. Because when I input text that beyond the elideWidth of metrics to TextField, fullText will not be updated. Therefore, you should connect text with fullText at least, just like this

                Connections {
                        function onTextChanged() {
                            if (text !== metrics.elidedText)
                                fullText = text
                        }
                }
                
                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