manipulate svg-grafic in QDialog

Need help, or want to share a macro? Post here!
Chri1
Posts: 70
Joined: Wed Oct 17, 2018 9:00 am

manipulate svg-grafic in QDialog

Postby Chri1 » Sun May 17, 2020 3:56 pm

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.
Chri1
Posts: 70
Joined: Wed Oct 17, 2018 9:00 am

Re: manipulate svg-grafic in QDialog

Postby Chri1 » Wed May 20, 2020 1:20 pm

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)
openBrain
Posts: 5625
Joined: Fri Nov 09, 2018 5:38 pm

Re: manipulate svg-grafic in QDialog

Postby openBrain » Wed May 20, 2020 6:10 pm

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.
Chri1
Posts: 70
Joined: Wed Oct 17, 2018 9:00 am

Re: manipulate svg-grafic in QDialog

Postby Chri1 » Thu May 21, 2020 10:44 am

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 ;)
openBrain
Posts: 5625
Joined: Fri Nov 09, 2018 5:38 pm

Re: manipulate svg-grafic in QDialog

Postby openBrain » Tue May 26, 2020 7:47 pm

Sorry for sparse replies. This isn't clear yet. Could you provide an example SVG and a simple mock up ?