Hi
I have a dialog (created with QT) with svg graphics (created with Inkscape), the grahics are integrated by styleSheet-property of an label.
Pressing various buttons in the dialog box also changes the used SVG files.
But:
I don't want to use a lot of SVG files, I want to draw everything in one file at different layers.
And in the dialog I want to change the visibility of the layers by code.
Or in general:
How can I change an svg by code (without changing the file itself) and use it in the dialog ?
Thanks.
manipulate svg-grafic in QDialog
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: manipulate svg-grafic in QDialog
Firstly the code to manipulate the svg-file:
Code: Select all
import xml.etree.ElementTree as ET
what = ..... svg # Path and filename
tree=ET.parse(what)
#Also possible: tree=ET.fromstring(svg - code)
root=tree.getroot()
for ding in root.iter('{http://www.w3.org/2000/svg}g'):
#print(ding.attrib, ding.get('style'))
ding.set('style','display:inline') # or unvisible: display:none
print(ding.get('style'))
tree.write(what)
Re: manipulate svg-grafic in QDialog
What are you (at the end) trying to achieve ? Can you give details/example/moke-up ?
ATM I'm not sure tampering the SVG DOM is the best approach.
ATM I'm not sure tampering the SVG DOM is the best approach.
Re: manipulate svg-grafic in QDialog
Trying to achieve:
I have a Dialog with some buttons. Every Button should show an explaining picture (always in the same label).
On the whole, the pictures are relative similar. the differences I lied on different layers and can be shown by switching the layers.
This works now by manipulating the svg-file by code and reload it in the dialog.
It is definitely easier than managing a lot of pictures (if I improve the design, I don't have to edit a lot of pictures. And it opens up further possibilities by manipulating the individual elements of the graphic)
But maybe its possible, to do this without always changing the file.
I just tried in QT to put the svg-code directly in the stylsheet-property - QT crashed......
I don't know if that would be really an advantage, there is also a little sporting ambition
I have a Dialog with some buttons. Every Button should show an explaining picture (always in the same label).
On the whole, the pictures are relative similar. the differences I lied on different layers and can be shown by switching the layers.
This works now by manipulating the svg-file by code and reload it in the dialog.
It is definitely easier than managing a lot of pictures (if I improve the design, I don't have to edit a lot of pictures. And it opens up further possibilities by manipulating the individual elements of the graphic)
But maybe its possible, to do this without always changing the file.
I just tried in QT to put the svg-code directly in the stylsheet-property - QT crashed......
I don't know if that would be really an advantage, there is also a little sporting ambition
Re: manipulate svg-grafic in QDialog
Sorry for sparse replies. This isn't clear yet. Could you provide an example SVG and a simple mock up ?