Visualization of dynamic c++ list with positions as set of Items in QML-app at corresponding positions.
-
Some c++ class periodically sends a list of items with positions inside (x and y). It needs to be visualized on grids and axis I've created in QML.
For representation of item I've prepared black rectangle in Rect.qml file.
Is it possible to:- represent each item using rect.qml (like appearance of item)
- not using paint(...) from QQuickPaintedItem and updatePaintNode(...) from QQuickItem respectively
- place each item in some QML container (like Rectangle) with corresponding (x and y) from list ?
I didn't find any straight way to do this.
I know i could use QGraphicsScene and QPainter with QMainWindow GUI without any "qml" but i want to use benefits of QML interface.
-
Some c++ class periodically sends a list of items with positions inside (x and y). It needs to be visualized on grids and axis I've created in QML.
For representation of item I've prepared black rectangle in Rect.qml file.
Is it possible to:- represent each item using rect.qml (like appearance of item)
- not using paint(...) from QQuickPaintedItem and updatePaintNode(...) from QQuickItem respectively
- place each item in some QML container (like Rectangle) with corresponding (x and y) from list ?
I didn't find any straight way to do this.
I know i could use QGraphicsScene and QPainter with QMainWindow GUI without any "qml" but i want to use benefits of QML interface.
@ilyaik How does the list of items look like ?
One way to implement would be using Connections. Set thetargetas your C++ class which I assume you have set as a context property. Then when ever the new list is sent through as signal, grab it inside the corresponding handler in QML. Once you get the list iterate over it and then setxandycoordinates of the Black rectangles. For this you can keep a list of Black rectangles in QML array. -
@ilyaik How does the list of items look like ?
One way to implement would be using Connections. Set thetargetas your C++ class which I assume you have set as a context property. Then when ever the new list is sent through as signal, grab it inside the corresponding handler in QML. Once you get the list iterate over it and then setxandycoordinates of the Black rectangles. For this you can keep a list of Black rectangles in QML array.@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
myListwith 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) } }myListhasxPosition(index)andyPosition(index)slots recpectively.And it works.
Thank you for help! -
@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
myListwith 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) } }myListhasxPosition(index)andyPosition(index)slots recpectively.And it works.
Thank you for help! -
I've faces a new problem.
If QList inside
myClasschanged it's values, but countmyList.countdidn't, Repeater doesn't updates. That's ok... strictly speaking the Repeater's modelmyList.countdidn't change.
I made a signal frommyClassupdateSignal.updateSignalemits when data inside list inmyClassis updated. In QML this signal is exposed inConnectionspart.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. -
I've faces a new problem.
If QList inside
myClasschanged it's values, but countmyList.countdidn't, Repeater doesn't updates. That's ok... strictly speaking the Repeater's modelmyList.countdidn't change.
I made a signal frommyClassupdateSignal.updateSignalemits when data inside list inmyClassis updated. In QML this signal is exposed inConnectionspart.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. -
No. Repeater doesn't renew without assigning model to 0 in
Connections. It seems like nothing changes for Repeater ifmyClass.countstays unchanged. -
So that's why i use assigning model to 0 in
Connectionsto force Repeater to renew itself when count stays unchanged.