Unsolved Saving QGraphicsScene (vector graphics PLUS IMAGE) to SVG
-
Hello,
I am creating a QGraphicsScene and adding several points (as tiny QGraphicsRectItem). I am also creating a path as QGraphicsPathItem. I am able to export this to SVG using the well documented method:
QSvgGenerator generator; generator.setResolution((int )dpi); generator.setFileName(afilename); QPainter painter; painter.begin(&generator); painter.setRenderHint(QPainter::Antialiasing); // myGraphicsScene is a subclass of QGraphicsScene myGraphicsScene->render(&painter); painter.end();
And that works fine. Output SVG is fine.
Then I am reading an image from file and convert it to a QBrush which I use to fillPath(), that is to flood-fill my path with this image/brush.
I can see the vector graphics and the filled-with-image path on my canvas just fine. I can also see same results when outputting as an image (PNG/JPG) using similar method as above.
BUT, I can not see the image in my SVG output file. Everything else is OK, path, rects. Just fine. But there is no image. And as far as I could understand by reading the output SVG text file, there is no mention of any image in that file.
Does anyone have any hints for solving this problem?
Thanks,
bliako -
Hi,
This might be outside of the static features of SVG tiny 1.2 specification implemented by the QtSvg module.
See here
-
Thanks for your reply. I found this link via the link you provided: [https://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static](link url) Which lists all the static features of SVG 1.2 as:
Feature String: http://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static User Agent Supports: All of the following features (described below) ... feature/1.2/#ConditionalProcessingAttribute" "http://www.w3.org/Graphics/SVG/feature/1.2/#Image" ... etc. For SVG viewers, "http://www.w3.org/Graphics/SVG/feature/1.2/#SVG-static" indicates that the viewer can process and render successfully all of the language features in the modules corresponding to the features listed above.
So, Image support is there as I understand it.
And I can confirm that if I do
QPixmap *myPixmap = new QPixmap(); myPixmap.load(imgfilename); ... Qpainter painter; painter->drawPixmap(0, 0, *myPixmap); ...
Then exported SVG file contains an
<image
element and I can view the image in gimp.However, if I add:
... QBrush *myBrush = new QBrush(*myPixmap); ... painter->fillPath(myGIPath->path(), *myBrush);
I can see the pixmap on my application's QGraphicsScene fine, but when I export to SVG, image is now missing.
Am I doing this last bit right?
-
Except that you don't need to allocate the brush on the heap. The line is fine.
Did you already check the bug report system ?