Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Placing dynamic QML element in another dynamic QML element.
Forum Updated to NodeBB v4.3 + New Features

Placing dynamic QML element in another dynamic QML element.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.7k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    Qnoobish
    wrote on last edited by
    #1

    Hello

    As my title says, I would like to create a dynamic element inside another dynamic element in QML.
    For example I would like to dynamically create a big blue Rectangle (as background) and in it I would like to place another red and smaller rectangle (as an Item; also dynamically created).

    Hopefully this would be possible in QML since for dynamic elements the Id can't be used. Any hints, examples or information is very welcome.

    Thanks in advance !

    In short, software is eating the world.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What do you actually mean by "dynamic element"? One loaded with Loader, or with .createComponent(), or one instantiated in C++?

      The procedure is quite simple in any case: you create the second object in QML defining the first object - and in the same way. So, for example, using Loader element:
      @
      // Your QML file:
      ...
      Loader {
      source: "Dynamic1.qml"
      }

      // Dynamic1.qml
      Rectangle {
      //your first rectangle
      Loader {
      source: "Dynamic2.qml"
      }
      }

      // Dynamic2.qml
      Rectangle {
      // Your second rectangle
      }
      @

      (Z(:^

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qnoobish
        wrote on last edited by
        #3

        Well I need to do this using QML only. So I suppose Loader or .createComponent() are my options.

        What I mean by dynamic elements is for example:
        Creating a number of TextEdit Items according to the data in a List. So If in the list I find a...let's say number 5, then I would need to create 5 TextEdit items with the posibility to read and write data, and identify each one of the dynamically created TextEdit items.

        I hope I make myself clearer this time. I will investigate further if the Loader element is useful for my purpose.

        In short, software is eating the world.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Sound more like a job for ListView or - even better - Repeater elements, then. You can access Repeater's elements by inspecting item.children, and ListView (or GridView) by checking out the model. You need to identify the elements either by index or objectName property, though - standard ids will not work.

          (Z(:^

          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