Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

qml gridlayout does not position last child



  • Hi.
    I want to add multiple custom items to GridLayout dynamically, but last item does not position properly. It goes to point (0, 0) of GridLayout.

    GridLayout {
                id: grid
                anchors.fill: parent
                columns: 5
    
                Component.onCompleted: fillGridItems()
            }
    

    And code for fillGridItems :

    function fillGridItems() {
            var comp = Qt.createComponent("../MyItem.qml")
            var dimension = upRect.width * itemWidthPercent
    
            for(var i = 0; i < 10; i++) {
                    for(var j = 0; j < 5; j++) {
                            var obj = comp.createObject(grid, {
    //                                                column: j,
    //                                                row: i,
                                                    "Layout.alignment": Qt.AlignHCenter | Qt.AlignVCenter,
                                                    width: dimension,
                                                    height: dimension,
                                                    source: Cte.itemsSources[i],
                                                    sourceSize: Qt.size(dimension, dimension)
                                                });
                            itemsList.push(obj);
                    }
            }
    }
    

    It looks like that the last item (i ==9 && j == 4), is not child of grid layout !

    What is the problem? Is this a bug?



  • Hi Majid,

    I'm experiencing the same annoying issue.
    Did you find a fix ?

    Thanks.

    Karim


  • Qt Champions 2017

    @Karim, It should absolutely work without any issue. Above code works without any issue. Have you tried with simple example ? Can you paste the example code.


Log in to reply