Important: Please read the Qt Code of Conduct -

Detecting lines and/or colors on an SVG (or other vector graphics) file

  • Hello,

    I'm working on a simple application that should display an indoors map on the screen and a 'dot' that will be moved around when the user (who holds the phone) moves around the building. Basically an indoors navigation system, to give it a fancy name.

    I was wondering if, using the Qt graphics system, it's possible to detect things like lines and colors on the displayed SVG file?
    So for instance if the dot bumps into a wall (a black line) the program would know not to draw the dot over the line but keep it behind it.
    Basically all i want is to add a little "intelligence" to it, even though this whole project is just for research and testing purposes.

    I haven't worked with the Qt graphics system directly a lot, but I do know that if i implement my own rectangles and graphics items using Qt then i could use the functions to detect the boundaries of the elements and overlapping and so on... I'd like to have that same functionality when dealing with loaded a loaded SVG file(s).

    Thanks in advance!

  • SVG is an xml-based file. You can open that file with a text editor. Than you can see the structure of it. Basically the idea would be to check in the file if you find the word <path />
    If so you have found a line.


       d="M 165.62651,39.043691 C 158.76058,39.0.............


    In this section you have all the information you will need. Namely the coordinates of the line.
    You can read those data and load them into an array. Than you will be able to draw the same objects on top of your picture using qt.

    you can try it by simply creating a svg-file with only one line in illustrator.

    I havent tried it myself so it might not be entirely accurate but i think it should work.

    I hope it was a bit helpful.

    Good luck

  • Thanks for the answer basil, I almost forgot you could open the SVG file with a text editor and look at the XML code!
    I'm working on the application right now and reading through the Qt graphics framework docs, I'll try extracting and using the path coordinate numbers as soon as I'm ready.

    I noticed the SVG-related classes (like QGraphicsSvgItem) have some interesting functions like setting/getting the element's XML ID which could be helpful!
    I think i should have done a little more research before making a new thread :)

    Will report back here if it works or not, thanks again.

Log in to reply