PDA

View Full Version : QML with C++ backend - dynamic components



benberli
4th September 2016, 12:08
I am quite new to QML and am trying to write some code that features dynamic components with a C++ backend.

Let's assume I want to write a program where:

The user presses a button that opens a dialogue where he fills in a name N, and position X, Y
When OK is pressed a component that is a rectangle with the text N from the dialogue is created at position X,Y with color C="blue"
N rectangles can be created by using the steps above (fully dynamic)
There is a C++ backed that has a list of these rectangles and can by some C++ logic change the X,Y,C properties of the rectangles or even add new rectangles or delete some created ones.
I've read probably all documents that I could google that describe QML and C++ integration but didn't find an example that was close enough to what I need.

I appreciate your guidelines of how to implement the desired behavior.

Thanks in advance!
Ben

anda_skoa
4th September 2016, 14:30
I would say you create a custom model that has X, Y and N for each entry and use a Repeater element in QML to create Rectangle elements for each entry in the model, using the model's data.

Cheers,
_

benberli
5th September 2016, 16:07
Thank you, this helped a lot and I have something basic working :)