SVG tooltips in QGraphicsView



  • I have looked through the QtSvg docs and can't find any pointers on what I want to achieve. I have an SVG that I currently display within a QGraphicsView and that works fine. What I want however is to mimic firefox's behaviour (I believe it also part of the SVG standard) that when moused over the elements title is displayed as a tooltip.

    It is trivial to ascertain which QGraphicsSvgItem is under the mouse but I cant find any details about how you would find out more information such as the element within the SVG file. I have attached a sample SVG file and firefox gives the behaviour I want.

    Thanks for reading.
    !http://www.dur.ac.uk/a.j.poole/all.svg(Example SVG)!



  • No SVG experience to speak of, but from the docs your most likely chance seems to be QSvgRenderer::boundsOnElement - provided you know the item IDs.



  • Thanks for the tip. Think I am going to have to manually parse the file to get element IDs and titles. But a manual test appears to work.



  • SVG support is not Qt's strong suit, I'm sorry to say. Hope you find a solution that works for you.



  • Could you please post your solution? I have the same problem to solve.
    How can you know whether the mouse is over a particular svg node? Using bounding boxes is definitely not sufficient.



  • Could you please post your solution? I have the same problem to solve.
    How can you know whether the mouse is over a particular svg node? Using bounding boxes is definitely not sufficient.



  • I agree that bounding boxes are not ideal as elements may have unsual geometries but in my case it is just about acceptable so I didn't go further in finding a better solution. I would love to hear about one if you find it however.

    What I do is this:

    1. Parse svg to find element ID and title.
    2. calculate each elements bounds with QSvgRenderer::boundsOnElement
    3. on mouse events check if element bounds contains the mouse position


  • I agree that bounding boxes are not ideal as elements may have unsual geometries but in my case it is just about acceptable so I didn't go further in finding a better solution. I would love to hear about one if you find it however.

    What I do is this:

    1. Parse svg to find element ID and title.
    2. calculate each elements bounds with QSvgRenderer::boundsOnElement
    3. on mouse events check if element bounds contains the mouse position

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.