Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    qml gridlayout does not position last child

    QML and Qt Quick
    3
    3
    525
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MajidKamali last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • K
        Karim last edited by

        Hi Majid,

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

        Thanks.

        Karim

        1 Reply Last reply Reply Quote 0
        • dheerendra
          dheerendra Qt Champions 2022 last edited by

          @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.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply Reply Quote 0
          • First post
            Last post