0
votes

I am trying the similar code to the tutorial, but I get 'QML Rectangle: Binding loop detected for property "width"' on the list view delegate. This happens only on messages where words are larger than listView.width and text wrapping happens. This happens all time. How can I fix it?

delegeate: Rectangle {
  id: delegateFrame
  width: Math.min(messageText.implicitWidth , listView.width)
  height: messageText.implicitHeight

  Label {
      id: messageText
      anchors.fill: parent
      text: model.text
      wrapMode: Label.Wrap
  }
}

I am using Qt 5.8.

EDIT

Changed as Felix suggested in his answer, however it only changed the "width" word in the warning to "implictWidth".

delegeate: Rectangle {
  id: delegateFrame
  implicitWidth: Math.min(messageText.implicitWidth , listView.width)
  implicitHeight: messageText.implicitHeight

  Label {
      id: messageText
      width: parent.width
      text: model.text
      wrapMode: Label.Wrap
  }
}
1
How do you define the ListView.width?derM
When you state, the warning happens, when the words are longer than the ListView's width, your delegateFrame.implicitWidth is bound to the listView.width, so it should have nothing to do with the messageText.implicitWidth. => With the snippet you show, we can't resolve the issue.derM

1 Answers

2
votes

The cause here is probably height: messageText.implicitHeight and anchors.fill: parent. Reason:

change label height --> change delegate hight --> change anchors --> change label height ...

QML detects those loops and interrupts them. In some cases, you have to live with those, because it's the only way to archive your layout.

In your case however, there might be a solution. You can try one of the following, and see if they work:

  • use implicitHeight and implicitWidth in the delegate. Sometimes those remove the warnings
  • Instead of using anchors.fill bind the width only: width: parent.width. Since you already adjust the parents height to the child, the child does not need to change it's height to the parent
  • Use Layouts. For example RowLayout. They provide advanced ways of placing items and use attached properties to adjust how items are displayed