Visualization of dynamic c++ list with positions as set of Items in QML-app at corresponding positions.
-
@p3c0 This is an idea!
List is a QList<struct {int x; int y}>But as it always happens... after 1 day of searching solution appears only after asking a question on forum =)
I did as you said: a C++ class
myList
with QList inside. I made this class as a context property. Class hasQ_PROPERTY (int count READ count NOTIFY countChanged)
that is the size of QList.
In QML part i've placedRepeater { model: myList.count; Rectangle { // black rectangle ... x: myList.xPosition(index) y: myList.yPosition(index) } }
myList
hasxPosition(index)
andyPosition(index)
slots recpectively.And it works.
Thank you for help! -
I've faces a new problem.
If QList inside
myClass
changed it's values, but countmyList.count
didn't, Repeater doesn't updates. That's ok... strictly speaking the Repeater's modelmyList.count
didn't change.
I made a signal frommyClass
updateSignal
.updateSignal
emits when data inside list inmyClass
is updated. In QML this signal is exposed inConnections
part.Connections { target: myClass onUpdateSignal { repeater.model = 0 repeater.model = myClass.count } } // And Repeater part Repeater { id: repeater model: 0 Rectangle { // black rectangle ... x: myList.xPosition(index) y: myList.yPosition(index) } }
It renews
repeater
.
But it seams that it's like a crutch.
Is there any proper way to renew Repeater?P.S.
repeater.update()
didn't help.