Using QSvgRenderer with QGraphicsObject, image is to large

  • Hello,

    I'm working with the Qt Graphics View Framework, and I would like to have graphics items which are partly displayed from SVG files. At the moment the SVG is not displayed correctly. This might be a bug, but I don't have a lot of experience on this so I might be missing something.

    What I have done is to create a subclass from QGraphicsObject, and this class contains a QSvgRenderer. I have created a sample file in InkScape which is read by the constructor and passed to the renderer. The paint method renders the image.

    When this object is added to a graphics scene the view box and boudingRect has the correct size according to what was set in InkScape. The image, however, is many times larger, and it is drawn outside the boundingRect. (I drew a line around it to see.)

    Is there anything that needs to be done to assure that dimensions are correct? Or is this a bug?

  • I found the missing element. When rendering I used the default bounds of the render method. This seems to be the bounds of the painter, and expected it to be the at least related to the SVG information.

    The display is correct when adding a second parameter:
    @renderer->render(painter, renderer->boundsOnElement(QLatin1String("layer1")));@

    It works now, but it still seems a bit strange. Wouldn't it be better if the default bounds was the size of the image?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.