Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSvgWidget and URIs: Can I emit a signal by clicking on a link in an SVG image?

QSvgWidget and URIs: Can I emit a signal by clicking on a link in an SVG image?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    What I would like to do is this:
    I can display an SVG image of a graph, which is generated by the Graphviz library, in a QSvgWidget (no problem there). Nodes and edges of the graph can have tooltips as well as URL properties. When the SVG file is displayed in a browser, the link specified by the URL is followed if one clicks on it. Instead, since it is being displayed in a widget and not a browser, I want to emit a QObject signal which would be connected to the parent of the QSvgWidget and cause it to display a popup window with additional data related to the node or edge.

    What is the best way to do this?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      The only way know is to read the XML /with XML class) and find the Id that are links.
      Then use
      QRectF QSvgRenderer::boundsOnElement(const QString &id) const
      to get the rects for the choosen Ids.
      Then use this rect list for mousePress event on a QSvgWidget subclass

      I did not find any access methods for SVG properties in the SVG classes.

      That said, Graphviz also supports HREF in the dot format so you can make labels
      "hotlinked"
      https://stackoverflow.com/questions/14155773/label-hyperlink-graphviz

      R 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        The only way know is to read the XML /with XML class) and find the Id that are links.
        Then use
        QRectF QSvgRenderer::boundsOnElement(const QString &id) const
        to get the rects for the choosen Ids.
        Then use this rect list for mousePress event on a QSvgWidget subclass

        I did not find any access methods for SVG properties in the SVG classes.

        That said, Graphviz also supports HREF in the dot format so you can make labels
        "hotlinked"
        https://stackoverflow.com/questions/14155773/label-hyperlink-graphviz

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by
        #3

        @mrjj Thanks very much, this was very helpful!

        In the meantime, I discovered that Graphviz can also output an HTML image map of a graph. Together with the information returned by QSvgRenderer::boundsOnElement function, I think I can do it.

        As to the link ID: Is this the tag name, or is there an attribute "id" for each SVG element? (I don't know much about SVG except that it is a special kind of XML format.)

        mrjjM 1 Reply Last reply
        0
        • R Robert Hairgrove

          @mrjj Thanks very much, this was very helpful!

          In the meantime, I discovered that Graphviz can also output an HTML image map of a graph. Together with the information returned by QSvgRenderer::boundsOnElement function, I think I can do it.

          As to the link ID: Is this the tag name, or is there an attribute "id" for each SVG element? (I don't know much about SVG except that it is a special kind of XML format.)

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Robert-Hairgrove
          Yes Graphviz is very nice. Many ways to do things.
          its the ID attribute all elements have.
          <path id="lineBC" d="M 250 50 l 150 300" stroke="red"

          lineBC in this case.

          Since the id allows us to get a rect to hit test with , it was possible to know it was clicked.
          However, i did not find other way to read say text of a text element to get any URL
          so i think you need to find out this by reading the XML/or the HTML.

          Well SVGs format is just plain XML. So it should not too complicated to dig out
          some URLS.

          R 1 Reply Last reply
          2
          • mrjjM mrjj

            @Robert-Hairgrove
            Yes Graphviz is very nice. Many ways to do things.
            its the ID attribute all elements have.
            <path id="lineBC" d="M 250 50 l 150 300" stroke="red"

            lineBC in this case.

            Since the id allows us to get a rect to hit test with , it was possible to know it was clicked.
            However, i did not find other way to read say text of a text element to get any URL
            so i think you need to find out this by reading the XML/or the HTML.

            Well SVGs format is just plain XML. So it should not too complicated to dig out
            some URLS.

            R Offline
            R Offline
            Robert Hairgrove
            wrote on last edited by
            #5

            @mrjj Thank you!

            mrjjM 1 Reply Last reply
            0
            • R Robert Hairgrove

              @mrjj Thank you!

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Robert-Hairgrove
              Np :)
              Just as a note. I used inkscape to fiddle with the SVGs.
              Its sorts of reverses the element Y pos if saved.
              So just in case you did use InkScape as that fooled me for some time.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved