Word wrap in QML rectangle



  • Consider the following code:

    Rectangle {
              id: message_row
              Layout.fillWidth: true
              Layout.fillHeight: true
    
              color: "transparent"
    
              RowLayout {
                anchors.fill: parent
                spacing: 0
    
                Rectangle {
                  anchors.fill: parent
                  color: "transparent"
    
                  Text {
                    id: message_text
                    text: getText()
                    font: tap_fonts.default_font
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
    
                    anchors.fill: parent
    
                    wrapMode: Text.WordWrap
                  }
                }
              }
            }
    

    What I am finding is that the message text is not always wrapping. Depending on what machine I am running on, or platform it either works fine, or the text is centered with the left and right ends truncated.

    Am I doing something wrong?



  • Hi! Could you please check if this also happens when the Text isn't placed in a RowLayout (actually in no layout at all)? Smells like QTBUG-33097.



  • @DRoscoe
    I run your code and figured out that you must need to define width and height of first Rectangle. So try it first and let me know if any issue come again..



  • @Vicky-Sharma That did the trick. Still not sure why it sometimes works without that such as on the iPad or some of our computers.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.