Michał Walenciak
Michał Walenciak

Reputation: 4369

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?

Upvotes: 1

Views: 531

Answers (2)

JarMan
JarMan

Reputation: 8287

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
    }
}

Upvotes: 2

Pavan Chandaka
Pavan Chandaka

Reputation: 12831

You can try using listview delegate.

May be you can use QObjectList-based Model, as said in below link

https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html

In your c++ code expose the required data from rectangles using Q_PROPERTY

Upvotes: 2

Related Questions