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. QML Text : How to know currently displaying characters ?
Forum Updated to NodeBB v4.3 + New Features

QML Text : How to know currently displaying characters ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 939 Views 1 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.
  • DonCoderD Offline
    DonCoderD Offline
    DonCoder
    wrote on last edited by
    #1

    When text truncated in Text element how to get the exact displayed Text from text Element. For example from the follwoing code ...

                Text {
                    id: txt
                    text: qsTr("ABCDEFGHIJKLMNOP")
                    maximumLineCount: 1
                    elide:Text.ElideRight
                    font.pointSize: 30
                    anchors.fill: parent
                    anchors.margins: 10
                    verticalAlignment: Text.AlignVCenter
                }
    

    Consider Text width is 300 , and the text truncated like "ABCDEFGH...." How can i get the string which is getting displayed out of complete string. I know truncated property will be true and will only tells text is truncated. But here i need Text which is displayed.

    E 1 Reply Last reply
    0
    • DonCoderD DonCoder

      When text truncated in Text element how to get the exact displayed Text from text Element. For example from the follwoing code ...

                  Text {
                      id: txt
                      text: qsTr("ABCDEFGHIJKLMNOP")
                      maximumLineCount: 1
                      elide:Text.ElideRight
                      font.pointSize: 30
                      anchors.fill: parent
                      anchors.margins: 10
                      verticalAlignment: Text.AlignVCenter
                  }
      

      Consider Text width is 300 , and the text truncated like "ABCDEFGH...." How can i get the string which is getting displayed out of complete string. I know truncated property will be true and will only tells text is truncated. But here i need Text which is displayed.

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @DonCoder Try FontMetrics.elidedText(). You would have to call it in onTruncatedChanged, I think.

      1 Reply Last reply
      0
      • DonCoderD Offline
        DonCoderD Offline
        DonCoder
        wrote on last edited by
        #3

        @Eeli-K : Correct, This would really help. Thanks
        a lot

        TextMetrics  {
                        id: t_metrics
                        text: qsTr("ABCDEFGHIJKLMNOP")
                        elide:Text.ElideRight
                        elideWidth: 250
                        font.pointSize: 30
                    }
        
                    Text {
                        id:txt
                        x: 316
                        y: 275
                        maximumLineCount: 1
                        anchors.margins: 10
                        anchors.fill: parent
                        verticalAlignment: Text.AlignVCenter
                        text:   t_metrics.elidedText
                        font.pointSize: 30
                    }
        
        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