Repeater and Delegate: ctx.fillStyle does not update color on DataChanged
-
Hallo,
in my QML file I have the following Repeater. When I emit onDataChanged in my QAbstractListModel the coordinates of the circles are updated and the circles are drawn on the new place. But, I also change the colors of the circles in the model and these colors are not updated (ctx.fillStyle = tcolor). They stay in their initial value:
(there are also other geometric objects, but that is not important for that)Repeater { id: partilcesreapeter model: Entrymodel delegate: chooser DelegateChooser{ id: chooser role: "type" DelegateChoice{ roleValue: "sphere"; delegate: Item{ id: sphereimage required property string tcolor required property int iparticle required property int semimajoraxis required property int semiminoraxis required property int xcoord required property int ycoord required property int angle width: 2.0*Number(semimajoraxis) height: 2.0*Number(semiminoraxis) x: Number(xcoord - semimajoraxis) y: Number(ycoord - semiminoraxis) Canvas { anchors.fill: parent onPaint: { var ctx = getContext('2d'); ctx.beginPath(); ctx.lineWidth = 1 ctx.strokeStyle = "black" ctx.fillStyle = tcolor ctx.ellipse(x,y,width,height) ctx.stroke(); ctx.fill(); } } rotation: Number(angle) DelegateChoice{ [...] } } } } }So, what can I do?
-
The Canvas is updated/repainter because its size changes but it doesn't know it should depend on
tcolor.
In your delegate, doonTcolorChanged: canvas.requestPaint().It won't change much here but is there a reason for not directly using
Canvasas your delegate here? -
The Canvas is updated/repainter because its size changes but it doesn't know it should depend on
tcolor.
In your delegate, doonTcolorChanged: canvas.requestPaint().It won't change much here but is there a reason for not directly using
Canvasas your delegate here?@GrecKo Thanks a lot!
in Canvas I wroteid: canvasSphereand before in delegate: Item{
onTcolorChanged: canvasSphere.requestPaint()Now the colors are updated.
I don't use Canvas directly, because there are different geometric objects, which I choose by
role: "type" DelegateChoice{ roleValue: "sphere";Or is there a simplier way to do this?
-
@GrecKo Thanks a lot!
in Canvas I wroteid: canvasSphereand before in delegate: Item{
onTcolorChanged: canvasSphere.requestPaint()Now the colors are updated.
I don't use Canvas directly, because there are different geometric objects, which I choose by
role: "type" DelegateChoice{ roleValue: "sphere";Or is there a simplier way to do this?
@Igor23 said in Repeater and Delegate: ctx.fillStyle does not update color on DataChanged:
I don't use Canvas directly, because there are different geometric objects [...]
My question was about the delegate inside the DelegatedChoice.
Instead of
DelegateChoice { delegate: Item { Canvas {} }you could doDelegateChoice { delegate: Canvas {}}if your Item doesn't hold more stuff. -
@Igor23 said in Repeater and Delegate: ctx.fillStyle does not update color on DataChanged:
I don't use Canvas directly, because there are different geometric objects [...]
My question was about the delegate inside the DelegatedChoice.
Instead of
DelegateChoice { delegate: Item { Canvas {} }you could doDelegateChoice { delegate: Canvas {}}if your Item doesn't hold more stuff. -
I Igor23 has marked this topic as solved