How to split svg image?



  • Hi, I have got an svg file and the svg file provides a country and its cities map. When I bring my mouse over the cities, I want to see city name. So, how can I split svg file or is there a better way? Thanks.



  • Hi! SVG is just XML so you can write a parser with Qt XML.



  • @Wieland thanks. I know SVG path coordinates. I just want to mouse over city and I want to see city name. I wrote this:

    ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr('Country SVG')
    
      Image {
        id: mapCountry
        source: 'qrc:/country.svg'
        MouseArea {
          anchors.fill: parent
          onClicked: {
            Qt.quit()
          }
        }
      }
    
      Path {
        id: firstCity
        startX: 0
        startY: 0
        PathSvg {
          path: 'M545.408,271.835c-0.276,0-0.514,0.209-0.812,0.594c-0.298,0.385-0.571,0.883-0.97,1.28 c-0.469,0.469-1.273,0.823-2.063,1.218c-0.395,0.197-0.768,0.397-1.062,0.561c-0.294,0.165-0.525,0.346-0.5,0.312 c-0.047,0.062-0.208,0.342-0.375,0.656s-0.356,0.697-0.563,1.094c-0.414,0.794-0.824,1.587-1.22,2.061 c-0.519,0.623-0.954,1.969-2.096,2.968c-0.41,0.358-0.525,0.729-0.626,1.156s-0.125,0.904-0.407,1.375 c-0.162,0.269-0.705,1.3-1.189,2.311c-0.242,0.506-0.461,1.02-0.626,1.438s-0.25,0.786-0.25,0.781c0,0.289-0.146,0.497-0.281,0.656 s-0.285,0.299-0.469,0.438c-0.368,0.276-0.827,0.538-1.281,0.78c-0.877,0.47-1.691,0.817-1.75,0.843 c-0.002,0.001-0.062,0.031-0.062,0.031l-2.845,1.717v0.031h-0.033l-2.876,1.498l-4.189,2.404h-0.031l-0.031,0.031l-2.97,1.092 l-0.062,0.031l-3.032,1.748l-0.439,1.688v0.031l0.124,1.312v0.031l0.499,1.531v0.062v0.062l0.123,2.781c0,0,0.016,0.717,0.03,1.469 c0.008,0.376,0.014,0.74,0.03,1.062c0.017,0.322,0.057,0.635,0.062,0.656c0.084,0.336-0.003,0.562-0.094,0.812 s-0.219,0.485-0.344,0.719c-0.25,0.468-0.531,0.875-0.531,0.875v0.031l-0.062,0.031c0,0-0.343,0.381-0.812,0.75 c-0.469,0.369-1.003,0.811-1.688,0.811c-0.545,0-1.063-0.237-1.5-0.439c-0.351-0.162-0.495-0.286-0.594-0.344c0,0-0.06,0-0.062,0 c-0.054-0.01-0.672-0.128-1.406-0.282c-0.383-0.08-0.783-0.164-1.125-0.251c-0.342-0.086-0.582-0.166-0.812-0.281 c0.015,0.008-0.275-0.076-0.594-0.125s-0.708-0.078-1.125-0.126c-0.834-0.094-1.702-0.188-2.25-0.345 c-0.755-0.216-3.191-0.613-3.281-0.627v0.031l-4-0.002c-0.016,0.032-0.127,0.263-0.344,0.562c-0.231,0.319-0.514,0.712-1,0.905 c-0.177,0.071-0.953,0.53-1.563,0.937c-0.609,0.407-1.125,0.78-1.125,0.78l-0.062,0.031l-0.062,0.031l-3.095,0.967l-0.062,0.031 l-2.845,1.373l-0.125,0.031h-0.094l-4.406-0.002l-2.719,0.155l-1.126,1.218l-0.595,2.469v0.031c0.004,0.027,0.109,0.84,0.218,1.781 c0.111,0.958,0.237,1.972,0.155,2.625c-0.115,0.924-0.252,4.125-0.252,4.125v0.094l-0.031,0.062c0,0-0.22,0.625-0.532,1.281 c-0.156,0.328-0.338,0.676-0.532,0.969c-0.193,0.293-0.376,0.538-0.75,0.688c-0.14,0.056-0.476,0.367-0.906,0.781 s-0.968,0.93-1.657,1.343c-0.97,0.581-1.526,0.626-2.031,0.749l1.061,2.751l0.031,0.031v0.031l0.968,1.813l0.031,0.031 c0.02,0.033,0.153,0.27,0.375,0.531c0.237,0.279,0.58,0.469,0.562,0.469c0.282,0,1.048-0.046,1.844-0.061s1.597-0.012,2.125,0.063 c0.943,0.136,1.735,0.455,2.437,1.157c0.726,0.726,1.937,2.439,1.937,2.439l0.125,0.156l-0.031,0.156l-0.127,3.156v0.188 l-0.094,0.125l-1.47,1.718l-0.407,1.562l0.78,1.594l0.031,0.031v0.031l0.843,2.156l1.093,1.689l3.156,0.002h0.125l0.125,0.062 l2.655,1.501l0.031,0.031l0.062,0.062l0.999,1.001l0.188,0.188l-0.033,0.229l-0.126,1.156v0.031l-0.407,1.906v0.125l-0.094,0.094 l-1.157,1.28l-0.001,2.5l1.687,2.157l1.874,2.376l0.125,0.156v0.156l-0.002,2.781c0,0-0.018,0.526-0.126,1.062 c-0.054,0.268-0.124,0.551-0.281,0.812c-0.157,0.261-0.477,0.531-0.875,0.531c-0.379,0-1.217-0.017-2.031-0.001 c-0.407,0.008-0.803,0.045-1.125,0.061c-0.322,0.017-0.599,0.025-0.625,0.031c-0.315,0.079-1.176,0.629-2.281,0.905 c-0.934,0.233-3.099,0.937-3.189,0.967l-0.062,0.031l-0.189,0.098l2.155,1.313l6.248,3.753l5.498,3.378l0.031,0.031l3.343,1.752 h0.031l2.437,1.063l1.844,0.782l2.095-2.093l0.125-0.125l0.156-0.031l2.875-0.342h0.031h0.031l6.125,0.003l2-0.468l0.658-3.562 v-0.031l0.346-3.719l0.031-0.125l0.062-0.094l1.439-2.155l0.062-0.125l0.156-0.062l2.689-1.061h0.031l0.031-0.031l5.563-1.372 l3.252-4.31l3.753-4.998l0.125-0.156l0.219-0.031l1.781-0.28l0.251-1.531l0.031-0.094l0.031-0.094l1.783-3.03l0.031-0.031v-0.031 l1.407-1.749c0-0.248,0.002-3.016,0.002-3.5c0-0.505,0.001-2.125,0.001-2.125c-0.034-0.14-0.734-2.996-0.873-3.969 c-0.034-0.237-0.168-0.372-0.5-0.531s-0.802-0.276-1.25-0.501c-0.016-0.008-0.085-0.031-0.25,0.031s-0.364,0.195-0.562,0.344 c-0.396,0.297-0.75,0.656-0.75,0.656l-0.029,0.061l-0.094,0.031l-2.782,1.529l-0.094,0.031l-0.094,0.031 c0,0-1.74,0.124-2.438,0.124c-0.274,0-0.563-0.145-0.719-0.344s-0.207-0.393-0.219-0.562c-0.024-0.339,0.062-0.625,0.062-0.625 l0.657-2.375v-0.031v-0.031l0.939-2.311l-0.25-0.5l-0.031-0.062l-1.343-1.845l-0.123-0.157l0.031-0.219l0.501-2.406l0.031-0.125 l0.062-0.094l2.158-2.749l0.031-0.062h0.031c0,0,0.357-0.358,0.719-0.75c0.181-0.196,0.379-0.391,0.5-0.562 c0.091-0.128,0.118-0.246,0.125-0.25c0.003-0.614,0.126-2.531,0.126-2.531v-0.062l0.031-0.062l0.626-1.906l0.031-0.062l0.031-0.062 l0.813-1.125l0.377-3.562v-0.031c0,0,0.073-0.43,0.189-0.969s0.231-1.144,0.501-1.594c0.374-0.623,1.239-2.143,2.096-2.999 c0.62-0.62,1.157-1.968,1.157-1.968v-0.031l0.031-0.031l1.877-3.78l0.125-0.25l0.281-0.031l2.906-0.373h0.031h0.031l4.375,0.002 h0.031l2.156-0.655v-0.219l0.656-0.031c0.105-0.118,0.263-0.275,0.531-0.625c0.348-0.454,0.697-1.08,0.72-1.219 c0.088-0.53,0.382-1.137,0.657-1.688s0.532-1,0.532-1l0.813-2.781v-0.035l0.001-2.281l-0.718-2.062l-0.031-0.125v-0.094 l0.251-2.031v-0.062l0.031-0.062c0,0,0.533-1.191,0.626-1.562c0.131-0.524,0.501-1.906,0.501-1.906l0.501-2.25l0.127-3.719v-0.031 l0.376-2.656v-0.062l0.031-0.031l0.626-1.906v-0.031l1.596-3.624l-0.842-3.25c0,0-0.252-1.139-0.374-1.625 c-0.002-0.007-0.138-0.276-0.281-0.562s-0.32-0.64-0.5-0.969c-0.342-0.624-0.624-1.133-0.655-1.188c0,0-1.022-1.23-1.905-1.782 c-0.985-0.616-1.907-1.102-3.624-1.471c-0.916-0.197-1.31-0.39-1.531-0.501S545.871,271.835,545.408,271.835z'
        }
      }
    }
    

    How can I use MouseArea for cities?



  • @Ibrahim said in How to split svg image?:

    Path

    Path is specifically for use by PathView. You don't have a PathView, so don't use Path here.

    There is no built-in solution for click-maps, you have to come up with your own solution.


Log in to reply
 

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