change the color of a SVG Image at runtime?

Discussion about recent product features & solutions!
7 posts • Page 1 of 1
kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

change the color of a SVG Image at runtime?

Post by kilianvp »

I want change the color of a SVG Image at runtime is that possible?

//Edit:

for example take a Symbol and "connect" with a alert color

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: change the color of a SVG Image at runtime?

Post by mkoller »

Yes, this is possible, as with all images. You select a color in Gedi to be the background-color of that shape. When you then change the backCol during runtime, all pixels with the backCol you selected in gedi will change to the newly set backCol.

See attached example panel https://www.winccoa.com/fileadmin/image ... camera.pnl
Attachments
camera.pnl
(1.5 KiB) Downloaded 242 times

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: change the color of a SVG Image at runtime?

Post by kilianvp »

Thank you! that worked, however alertCamUna isn't working

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: change the color of a SVG Image at runtime?

Post by mkoller »

You mean a blinking color? Yes that doesn't work since this would be too expensive. We really change the pixels of the image one by one.
If it would be done too often, your CPU would go mad.
You could try to do the blinking via script, if that is acceptable in your project.
E.g. while ( alarm ) { backCol = "red"; delay(1); backCol = "green"; delay(1); }
Or you could use an animated GIF instead.

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: change the color of a SVG Image at runtime?

Post by kilianvp »

it's possible to add a new function for SVGs? SVG is different because the color is just an attribute and you can do this via QT very easily

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: change the color of a SVG Image at runtime?

Post by mkoller »

Depending on the complexity of the SVG this could still be expensive. On every color change the SVG would needed to be rendered again.
Beside this, we use QSvgRenderer, which does not provide access to the internal DOM tree, therefore we can not change any attribute.
The only thing I can imagine would be to allow animated SVGs, which would still have the pontential problem I described above, and you would still need to load different SVGs depending on the alarm status - similar what you can already do with an animated gif.

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: change the color of a SVG Image at runtime?

Post by kilianvp »

oh ok thank you! i solved that issue by draw everything with polylines

7 posts • Page 1 of 1