PDA

View Full Version : How to make QSvg Format Images



Sergex
6th October 2011, 12:46
Hello,

I am displaying an image in my MainWindow which is generated in a function that returns the image. Then in my GraphicsItem class, the image generated is passed as a parameter to the class.
In my paint method I simply do this:

void myGraphicsItem::paint(QPainter* painter, ....)
{
painter->drawImage(boundingRect(), m_itemImage);
}

I am looking for a way to use Svg Format images instead but I am having trouble understanding how to create an SVG image to display in my interface. What is the proper way of creating an SVG image instead of a regular image. I tried using QSvgGenerator in my paint method since it needs a QPainter but I don't quite understand how to use it. In my image generator function I make the image
creating it like:
myImage = new QImage(IMAGE_QUALITY_X, IMAGE_QUALITY_Y, QImage::Format_Indexed8); and then using scanline and return the image.

Could someone please help me out a bit to get on the right track I woudl really appreciate it!
Thanks.

pkj
6th October 2011, 14:24
Sergex, SVG is an open image format. There are a few open source project like delineate to convert from other formats to svg. However, I don't know how it performs as I never used it. A very popular tool to make svg is inkscape.
As for using SVG in qt, refer QSvgRenderer and QSVGGraphicsItem. QSvgRenderer::load will load the image, say from a location or memory. QSvgGraphicsItem::setSharedrenderer(QSvgRenderer*) will then use that renderer. There are qt examples. Have a look at them too.