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.4k Views
  • 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 10 Feb 2019, 13:53 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 10 Feb 2019, 16:06 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 10 Feb 2019, 17:44
      1
      • M mrjj
        10 Feb 2019, 16:06

        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 10 Feb 2019, 17:44 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.)

        M 1 Reply Last reply 10 Feb 2019, 17:54
        0
        • R Robert Hairgrove
          10 Feb 2019, 17:44

          @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.)

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 10 Feb 2019, 17:54 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 10 Feb 2019, 18:12
          2
          • M mrjj
            10 Feb 2019, 17:54

            @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 10 Feb 2019, 18:12 last edited by
            #5

            @mrjj Thank you!

            M 1 Reply Last reply 10 Feb 2019, 18:15
            0
            • R Robert Hairgrove
              10 Feb 2019, 18:12

              @mrjj Thank you!

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 10 Feb 2019, 18:15 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

              1/6

              10 Feb 2019, 13:53

              • Login

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