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. TextMetrics elideWidth is not working propertly on Android
Forum Updated to NodeBB v4.3 + New Features

TextMetrics elideWidth is not working propertly on Android

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 1.1k 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.
  • L Offline
    L Offline
    literA2
    wrote on last edited by literA2
    #1

    I created a component with Text and TextInput and I wanted to elide the text of TextInput using TextMetrics however, it didn't work because I am getting 0 width from its parent.

    PS: this only happened in Android, while in iOS it is working fine.

    Item {
      id: comp
      implicitWidth: parent.width
    
      RowLayout {
         anchors { left: parent.left; right: parent.right }
         Text {
            id: label
          }
    
          ColumnLayout {
             Layout.fillWidth: true
    
             TextInput {
                id: input
                Layout.fillWidth: true
                Layout.preferredWidth: implicitWidth - 2
              }
    
              TextMetrics {
                 elideWidth: input.width - 10
               }
    
               Rectangle {
                 id: recLine
                 Layout.fillWidth: true
                 height: 3  
               }
           }
       }
    }
    

    My problem is eliding of text didn't work because the input.width returns 0.

    Any advise how to get the dynamic width of the textInput to set it TextMetrics elideWidth?
    Is there a way that the TextMetrics will be created only after the TextInput?

    Thanks.

    UPDATE:
    *** I tried explicitly set the elideWidth, it turned out that the TextInput.width - 10 is still longer than the textinput width, that is why it didn't elide the text. How did it happened?
    However in iOS, TextInput.width - 10 is already enough to elide the text.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      literA2
      wrote on last edited by literA2
      #2

      Hi, after exerting few more hours, I was able to resolved the issue by setting font.pointSize into TextMetrics.

      It appears that the elideWidth on Android needs to explicitly set font.pointSize unlike in iOS.

      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