Qml text wrap (max width)

后端 未结 7 1789
抹茶落季
抹茶落季 2021-02-19 02:56

I would like to put text inside a bubble, and I want that my bubble be equal to the text width, but if the text length is too long, I would like the text to wrap automatically a

7条回答
  •  别跟我提以往
    2021-02-19 03:37

    i did not use state, but i use the idea of dummy text to have width. thanks

    my code :

                    Rectangle{
                    id:messageBoxCadre
                    width: (modelData.messageLength>25)? (wrapper.width - 20): messageBox.width+10
                    height: messageBox.height+5
                    color: modelData.myMessage ? "#aa84b2":"#380c47"
                    radius: 10
    
                    Text {
                        id:messageBox
                        width: (modelData.messageLength>25)? (wrapper.width - 20): dummy_text.dummy_text
                        text: ''+modelData.message+' '
                        wrapMode: "WordWrap"
                    }
    
                    Text {
                          id: dummy_text
                          text: ''+modelData.message+' '
                          visible: false
                      }
    
                }
    

提交回复
热议问题