Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Adding to GridLayout dynamically
Forum Updated to NodeBB v4.3 + New Features

Adding to GridLayout dynamically

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 951 Views
  • 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.
  • K Offline
    K Offline
    krobinson
    wrote on last edited by krobinson
    #1

    I am trying to create some objects and add them to a GridLayout dynamically. I have a couple of questions on how to pull it off.

    I have the GridLayout created.

    GridLayout
    {
        id: grid
        anchors.fill: parent
        rowSpacing: 2
        columnSpacing: 2
    }
    

    I am creating objects to populate it like this

    var object = Qt.createComponent("MyObject.qml");
    var instance = object.createObject(grid);
    

    Will this actually add the object to the grid? How can I set Layout properties on the object, for example Layout.fillHeight?

    ODБOïO 1 Reply Last reply
    0
    • K krobinson

      I am trying to create some objects and add them to a GridLayout dynamically. I have a couple of questions on how to pull it off.

      I have the GridLayout created.

      GridLayout
      {
          id: grid
          anchors.fill: parent
          rowSpacing: 2
          columnSpacing: 2
      }
      

      I am creating objects to populate it like this

      var object = Qt.createComponent("MyObject.qml");
      var instance = object.createObject(grid);
      

      Will this actually add the object to the grid? How can I set Layout properties on the object, for example Layout.fillHeight?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @krobinson hi,

      see this exemple from http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html

      function createSpriteObjects() {
          component = Qt.createComponent("Sprite.qml");
          sprite = component.createObject(appWindow, {"x": 100, "y": 100});
      
          if (sprite == null) {
              // Error Handling
              console.log("Error creating object");
          }
      }
      
      1 Reply Last reply
      0
      • K Offline
        K Offline
        krobinson
        wrote on last edited by krobinson
        #3

        After a bit more research I have realized that I am creating a Component object. So I cant just set the layout attached property on there. I need to access the actual item defined in the Component. How can I do that? Doing it by name just seems to be undefined.

        console.debug(instance.myItemName)
        

        That just returns undefined. How do I access the internal items in the component?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved