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

Text alignment issues inside ColumnLayout

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2: Important P2: Important
    • None
    • 5.4.1, 5.7.0
    • Quick: Layouts
    • Mac OS X 10.10.2
      Windows

      When Text element is placed inside ColumnLayout and it's text property is changed to string having different length, text gets drawn outside item's bounds.

      Here's the example:

      import QtQuick 2.4
      import QtQuick.Controls 1.3
      import QtQuick.Window 2.2
      import QtQuick.Dialogs 1.2
      import QtQuick.Layouts 1.1
      
      ApplicationWindow {
          title: qsTr("Label Alignment Test")
          width: 300
          height: 200
          visible: true
      
          ColumnLayout {
              anchors.centerIn: parent
      
              Button {
                  anchors.horizontalCenter: parent.horizontalCenter
                  text: qsTr("Next")
                  onClicked: _text.messageIndex += 1
              }
      
              Text {
                  id: _text
                  readonly property var messages: [
                      qsTr("Loooooooong message"),
                      qsTr("Short message")
                  ]
                  property int messageIndex: 0
      
                  horizontalAlignment: Text.AlignHCenter
                  text: messages[messageIndex % messages.length]
      
                  Rectangle { // Highlight text bounds
                      anchors.fill: parent
                      color: "#7fff0000"
                  }
              }
          }
      }
      

      When application starts, the long message is displayed, and everything is drawn correctly (semi-transparent red rectangle highlights actual bounds of the Text item):

      When "Next" button is clicked the first time, long message is replaced with the short one, and text is shifted to the right, so that it partly resides beyond item's bounds:

      After the second click on "Next" button message is switched back to short version, and now text is drawn to the left from where it should be:

      Text alignment works fine if Column is used instead of ColumnLayout in the above example.

      The attached ZIP archive contains the example project.

        1. LabelAlignmentTest.zip
          3 kB
        2. AfterSecondTextChange.png
          AfterSecondTextChange.png
          28 kB
        3. AfterFirstTextChange.png
          AfterFirstTextChange.png
          27 kB
        4. AfterAppStarted.png
          AfterAppStarted.png
          28 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            smd Jan Arve
            tonygluk Anton Karandeev
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes