QGraphicsSvgItem control size
-
Question
What's the proper way of setting a "scale offset" or "resize offset" when working withQGraphicsSvgItem
to control how big the rendered SVG is in scene coordinates? My source SVG has a size/viewbox of0, 0, 24, 24
and therefore the rendered SVG is only24x24
in size - but I'd like it to be larger.
I started dicking around with retrieving theQSvgRenderer
of theQGraphicsSvgItem
usingQGraphicsSvgItem::renderer()
and then usingQSvgRenderer::setViewBox()
but that didn't lead me anywhere near what I am after as that just changes the viewbox of the resulted rendering.Basically I am looking for something such as
QGraphicsSvgItem::setScaleOffset()
orQSvgRenderer::setSize()
.Background
Currently I have a custom class namednode
that inherits fromQGraphicsItem
. Essentially it paints itself as a rectangle with rounded corners, drop shadow and an icon (in the top left corner of the item's rectangle).So far I had a
QIcon
member in mynode
class and inside ofnode::paint()
I useQIcon::paint()
to paint the icon. This works great both in theory and practice.
The icon I am painting is an SVG image. But due to the current way of painting aQIcon
it looks bad at any zoom level other than 100% as the rastered icon is being scaled when the user manipulates the zoom value.
To solve this issue, I removed myQIcon
member and added aQGraphicsSvgItem
child item to mynode
class.
I managed to get everything working (as in: The SVG is successfully being rendered as part of mynode
class). Also the scaling works as expected: I can zoom in an out and the icon now always looks great.However, my issue is that the source SVG I have has a default view port of
0, 0, 24, 24
. The resulting icon is too small in reference to mynode
rectangle. Therefore, I set out to find a way of how to manually add a scale factor to my SVG so that the rendered icon is larger relative to thenode::boundingRect()
while also keeping the already working zoom scaling stuff.Unfortunately, I couldn't find a way of how to do this.
-
Hi,
I don't know either but what about nuking the viewport before loading the file ?
-
@SGaist said in QGraphicsSvgItem control size:
I don't know either but what about nuking the viewport before loading the file ?
Could you elaborate a bit more what your suggestion consists of?
-
SVG being XML, you could modify the view port as you see fit before loading it. But I may have misunderstood the issue at hand.
-
Hi
If you open the SVG in say inkscape and change its page size (ViewBox) does it then
work as expected in your app ?Im not sure i understand what the goal since QSvgRenderer::setViewBox() did change the rendered size for me with QIcon so are we looking for something else ?