2

I'm using QGIS-2.4.0 to developing an application.

I created my own custom MapCanvasItem for showing SVG. It is great to load a SVG from symbol library that QGIS provides(such as d:\QGIS Chugiak\apps\qgis\svg\symbol\poi_cave.svg), or a SVG file that QGIS Composer exports.

But when I created a SVG using Adobe Illustrator or Inkscape on my own, the application broke down to loading a SVG. I tested the SVG file created by Illustrator/Inkscape, it is well to display in QT project when I create a class Inheritanced from QgraphicsItem.

I don't know why, Can anyone help me? Here is my code to rewrite the function from QgsMapCanvasItem:

void TFMapCanvasSvgItem::paint(QPainter* painter)
{        
  if (!painter)
  {
    return;
  }
  QImage svgImage(50, 40, QImage::Format_ARGB32);
  QPainter imagePainter(&svgImage);
  mSvgRenderer.render(&imagePainter);
  painter->drawImage(QRect(0, 0, 100, 80), svgImage, QRect(0, 0, 100, 80));
}    

EDIT more:

The SVG symbol created by Illustrator/Inkscape couldn't be used in QGIS API application, but could be used in QGIS release software(such as Symbol selector, SVG annotation), as showed in 1.PNG, 2.PNG.

1.PNG enter image description here

2.PNG enter image description here

1 Answer 1

1

QGIS supports SVG but not as fully as QT. The SVG module in QT supports SVG, no matter what software generated. But QGIS API doesn't support arbitrary SVGs.

After I tried, QGIS API do not supports SVGs that have line. Even there is SVG in symbol library, it is useless if its part layer is line(or linear). Here is how to create a SVG using Adobe Illustrator.

First one is using stroke way to create a rectangle. enter image description here

So If you try to create a Rectangle, do not using Rectangle Tool to draw a rectangle and then stroke the four line of it. The right way to draw a rectangle is using two layers superpose to display the result.

Second one is using two layers to create a rectangle, one layer is a black rectangle, another one is a white rectangle that is smaller than black one. enter image description here


And, the result is:

using stroke one: enter image description here result: Break! enter image description here


using No stroke one:

enter image description here

result: OK! enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.