Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QSvgRenderer with QGraphicsObject, image is to large
Qt 6.11 is out! See what's new in the release blog

Using QSvgRenderer with QGraphicsObject, image is to large

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eirikm
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eirikm
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved