Kevin yudo
Kevin yudo

Reputation: 233

Qt/QML How to wrap text in Text Element whick is in Listview

I have ListView like :

 Rectangle {
            width:(parent.width)
            height: (parent.height/3)*2
            border.color: "lightsteelblue"
            border.width: 2
            color:"lightgrey"
            radius: 3
            ListView {
                id:malzemelist
                spacing: dp(6)

                clip:true
                orientation:ListView.Vertical
               flickableDirection: Flickable.VerticalFlick
               boundsBehavior: Flickable.StopAtBounds
                anchors.fill: parent
                model:malzememodel
                delegate: malzemecomp
                focus:true

            }
        } 

I have an model.I have fill my model When a click the button like model.append({mytext:"blalaladdd"}).I have set mytext to text in delage.I works but if my text is too long , wrap mode is not working.By the way I have set wrapmode:Text.Wrap.What is the problem...

mydelegate code is :

   Component {

        id:malzemecomp

        RowLayout
        {
            height: dp(16)
            width: parent.width
            Text {
                id: malzemeresultxt
                font.pixelSize: dp(12)
                text:malzeme
                wrapMode: Text.Wrap
                width: parent.width-dp(17)


            }
            Image {
                id: maldeleteimg
                 height: dp(16)
                 width:  dp(16)
                fillMode: Image.PreserveAspectFit
                source: "/Images/rejectmalzeme.png"
                Layout.alignment: Qt.AlignRight

                MouseArea {
                    anchors.fill: parent
                     onClicked: {
                         console.log(malzememodel.count+"/"+index);
                          TaskResult.taskresult.malzemeler.splice(index,1);
                          malzememodel.remove(index);
                          var seri=TaskResult.taskresult.serilaze();
                          console.log(seri);

                     }
                }
            }
        }

    }

Upvotes: 0

Views: 2037

Answers (1)

rsht
rsht

Reputation: 1582

You are supposed to use Layout.xxx properties instead of width/height/anchors when using RowLayout. Delete your width property from Text and use either Layout.maximumWidth with your previous width value or simply put Layout.fillWidth: true.

Here is some working QML snippet

Upvotes: 1

Related Questions