Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to display SVG in Qt(5.3) TextEdit without loosing quality?

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

This is basic code which I use for displaying svg:

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

and it's not ok because image is rasterized before resizing to width and height values(50,50).

This code works perfect on all resolution:

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

because image is drawn in exact dimensions which is needed!

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

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

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

Maybe there is some other way to accomplish this?

like image 812
DuhRobot Avatar asked Jan 23 '26 07:01

DuhRobot


1 Answers

The only solution is to provide the image size as part of the image url, and reimplement QTextDocument::loadResource or QTextEdit::loadResource in a derived class. Your image element would then look like:

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

You can parse the url in your implementation of loadResource.

like image 119
Kuba hasn't forgotten Monica Avatar answered Jan 26 '26 01:01

Kuba hasn't forgotten Monica