Is it possible to render SVG in Qt (5.3) TextEdit without quality loss?

I have a svg image with these attributes: viewBox="0 0 100 100"

This is the basic code I am using to display the svg:

Image{
  width: 50
  height: 50
  source: "test.svg"
}

      

and this is not normal because the image is rasterized before resizing to the width and height values ​​(50.50).

This code works great at any resolution:

Image{
  width: 50
  height: 50
  sourceSize.width: width
  sourceSize.height: height
  source: "test.svg"
}

      

because the image is drawn in the exact dimensions that are needed!

Is it possible to get the same functionality in TextEdit where the tag is used <img>

?

<img src="test.svg" width="50" height="50">

      

This code doesn't work because sourceSize cannot be set ... and the image is rasterized before resizing and displaying ...

Maybe there is another way to do this?

+3


source to share


1 answer


The only solution is to provide the image size as part of the image url and override QTextDocument::loadResource

or QTextEdit::loadResource

in a derived class. Then your image element will look like this:

<img src="test.svg?50x50" width="50" height="50" />

      



You can parse the url in your implementation loadResource

.

+1


source







All Articles