Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-18627

Elide has unexpected effect on Text's implicitWidth

    XMLWordPrintable

Details

    • 6e5a642c9484536fc173714f560f739944368cf5

    Description

      A Text element's implicitWidth should be the width that allow all of its text to be shown. Thus setting an explicit width that results in the text being truncated should have no effect on the implicitWidth, even if "elide" is enabled.

      Run the code below. Note that the console printout is

      67
      63
      0
      

      while the expected result is 67 in each case, as is the case if the "elide: Text.ElideRight" line is commented out.

      CheckBox.qml

      import QtQuick 1.1
      
      Item {
          id: checkbox
      
          implicitHeight: 30
          implicitWidth: button.implicitWidth + label.implicitWidth + spacing*3
          property alias theLabel: label.text
          property real margin: 5
          property real spacing: label.text.length > 0 ? 5 : 0
      
          Rectangle {
              id: button
              anchors.left: parent.left
              anchors.top: parent.top
              anchors.bottom: parent.bottom
              implicitWidth: height
              color: "green"
          }
      
          Text {
              id: label
              anchors.left: button.right
              anchors.leftMargin: spacing
              anchors.right: parent.right
              anchors.verticalCenter: button.verticalCenter
              elide: Text.ElideRight
              Rectangle { color: "red"; opacity: 0.2; anchors.fill: parent }
              Component.onCompleted: print(implicitWidth)
          }
          Rectangle { color: "yellow"; opacity: 0.2; anchors.fill: parent }
      }
      

      main.qml

      import QtQuick 1.1
      
      Rectangle
      {
          width: 400
          height: 400
      
          Column {
              spacing: 5
      
              CheckBox {
                  theLabel: "Hello World"
              }
      
              CheckBox {
                  theLabel: "Hello World"
                  width: 100
              }
      
              CheckBox {
                  theLabel: "Hello World"
                  width: 200
              }
      
              Rectangle {
                  color: "red"
                  width: 100
                  height: 10
              }
          }
      }
      

      Attachments

        1. snapshot1.png
          snapshot1.png
          4 kB
        2. snapshot2.png
          snapshot2.png
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes