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. How to use repeater with Shape+ShapePath?
Forum Updated to NodeBB v4.3 + New Features

How to use repeater with Shape+ShapePath?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.0k 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    I have a model that is just a list of dict objects that have x and y values in them. The Qt Documentation for Shape says:

    As a general rule, scenes should avoid using separate Shape items when it is not absolutely necessary. Prefer using one Shape item with multiple ShapePath elements over multiple Shape items.

    So I want to use a repeater, something to this effect:

    Shape {
        id: root
        Repeater {
            model: myModel
            ShapePath {
                startX: modelData.startX
                startY: modelData.starty
                PathQuad {
                    x: modelData.width
                    y: modelData.height
                    controlX: modelData.width / 2
                    controlY: modelData.height / 2
                }
            }
        }
    }
    

    but I get this error on the first line of the ShapePath item: QML Component: Delegate must be of Item type

    How can I create multiple ShapePaths based on a model?

    https://alaskafamilysystems.com/

    1 Reply Last reply
    1
    • K Offline
      K Offline
      Konstantin Schraubek
      wrote on last edited by Konstantin Schraubek
      #2

      There is a way, but i dont quite like it. But it works. Shapes added this way will not automaticly update when used with custom QAbstractListModel

      Shape{
      	id: shape
      	anchors.fill: parent
      			
      	Repeater{
      		id: repeater
      		model: myModel
      			delegate: Item{
      				property ShapePath s: ShapePath{					
      				strokeWidth: 2
      				startX: model.x
      				startY: model.y
                                      PathLine{x: model.x2; y: model.y2}
      				}
      				Component.onCompleted: {
      					shape.data.push(s)
      				}
      			}
      		}		
      	}
      }
      
      1 Reply Last reply
      1

      • Login

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