qtqmlqt5model-view

QML: Canvas like a view


I have a set of rectangles provided by c++ backend, and I'd like to paint each of them on qml side with some extra decorations, colors opacity etc (respecting rectangles' positions and sizes).

I was hoping for some special kind of view which would accept a model containing all these rectangles and then would use them in delegates to define items' positions and sizes.

The best I was able to find is 'Canvas' which I may use to fulfill my needs, but maybe there is something more suitable?


Solution

  • A Repeater can accept a model and instantiate your Rectangles at any size/position.

    Repeater {
        model: rectangleModel    // Comes from C++
    
        delegate: Rectangle {
            x: model.x
            y: model.y
            width: model.width
            height: model.height
        }
    }