Qml: Delegate / Model component for floating model elements

I have a dynamic set of QML components (they are based on / combine various controls like images, labels, etc.) that appear at "arbitrary" positions in the parent control. The position of each component is determined by the underlying object (C ++). Currently I create and remove these components by creating dynamic objects , each time a new base object is created or deleted.

While this works, it would be much easier to use the delegate / model schema with a basic QAbstractItemModel . Is there a built-in component for this, eg. a component that allows you to freely position QAbstractItemModel items?

[EDIT]: Here is a picture of what I mean:

enter image description here

Hello,

+3


source to share


1 answer


You can use Repeater

which is usually used with row or column to pave everything, but it will also work for stand-alone items.

In addition to this, you also have signals for added and removed items.



  Repeater {
    model: 20
    delegate: Rectangle {
      width: 50
      height: 50
      color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      MouseArea {
        anchors.fill: parent
        onPositionChanged: {
          parent.x += mouseX
          parent.y += mouseY
        }
      }
    }
  }

      

+3


source







All Articles