Binding loop detected for width/height



  • I'm trying to setup a GridView in order to fill the available space with an integer number of cells. I can't reproduce the behavior of standard QWidget where the layouts resize according to the children sizes.

    I have:

    1. a Rectangle which is the "container" of my GridView
    2. the GridView gets the orientation of the rectangle and sets the cell size
    GridView {
            anchors.fill: parent
            cellWidth: Math.min(parent.width, parent.height) == parent.width ? parent.width / 3 : cellHeight
            cellHeight: Math.min(parent.width, parent.height) == parent.width ? cellWidth : parent.height / 2
            model: model
            delegate: delegate
        }
    

    it works, but at run-time I get:

    QML GridView: Binding loop detected for property "cellHeight"

    I don't understand why there is this loop. The assignments are mutually exclusive.

    By the way, how to center the GridView content? It fills the available space from left-to right.


  • Moderators

    @Mark81
    The cellHeight when changes updates the cellWidth in this line:

    cellWidth: Math.min(parent.width, parent.height) == parent.width ? parent.width / 3 : cellHeight
    

    this cellWidth change re-evaluates the binding and updates the cellHeight in this line:

    cellHeight: Math.min(parent.width, parent.height) == parent.width ? cellWidth : parent.height / 2
    

    And this goes on foreever and hence the error.

    By the way, how to center the GridView content? It fills the available space from left-to right.

    How do you want it to appear ? Can you share some image ?


Log in to reply
 

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