Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Implementing SVG Editor with Qt > 5.x



  • Hi,
    I have been researching about how to load and edit an SVG file from Qt.

    I'm already aware that it's possible to load an SVG file created using an editor like Inkscape and that you can render and save a QGraphicsScene as an SVG file. My challenge is in the middle of the workflow: is it possible to edit the nodes of an SVG element that is part of an SVG file that I just loaded from a Qt implementation?

    I was looking for examples related to the edition process with no luck. Is it possible to transform SVG items as QGraphicsItems to modify them? or any other approach in that direction?

    Thank you for any hint.


  • Moderators

    @xtingray said in Implementing SVG Editor with Qt > 5.x:

    is it possible to edit the nodes of an SVG element that is part of an SVG file that I just loaded from a Qt implementation?

    no, and this is by far not a trivial task
    You will need to parse each SVG (XML) node and create a custom item with corresponding handles. When saving the changes you will need to transform your items back to a valid SVG.


  • Lifetime Qt Champion

    Hi
    If you need to handle more than a few SVG elements/constructs, using a lib is
    recommended.
    http://svgpp.org/

    Also, can I ask what types of edit you need to perform ?



  • @mrjj The goal is to allow users to load SVG files from my application to make little changes to the objects, including to edit the nodes of the elements, change their colors, group and ungroup , etc.

    I'm aware this is not a trivial implementation, I'm just researching what is the state of the art related to SVG edition from Qt.


  • Moderators

    @xtingray said in Implementing SVG Editor with Qt > 5.x:

    I'm just researching what is the state of the art related to SVG edition from Qt.

    simple: there is none :)
    Qt's SVG capabilities are just in displaying them.

    The rest can be achieved by parsing the XML source of the SVG.

    So my advice to start with:

    1. learn the SVG specification (as much as you can)
    2. learn Qt's XML classes
    3. then think about creating an appropriate structure to read the SVG data into
    4. use this structure for manipulating via UI elements (QtWidgets, QML)
    5. save the structure back to valid SVG


  • @mrjj Can we confirm that editing SVG file with Qt is not a good option ?


  • Lifetime Qt Champion

    @Parvathy2020

    Hi
    Yes we can confirm
    that out of the box,
    Qt editing features for SVG is very limited.

    We can edit an SVG in a generic way (since its XML)
    but for anything more serious than changing a
    color, using a lib will be much more fun/rewarding/easy.



  • @Parvathy2020 said in Implementing SVG Editor with Qt > 5.x:

    @mrjj Can we confirm that editing SVG file with Qt is not a good option ?

    Editing an SVG "with Qt" just isn't an option. Qt is a general purpose framework, and being a graphics editor is too specific to be useful to have as part of a general purpose tool set. By all means, feel free to use Qt for XML parsing, and for the GUI, etc. It'll work fine as some parts of a graphics editor. But you'll need to write the actual graphics editor parts.


Log in to reply