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. QGraphicsSvgItem control size
Forum Updated to NodeBB v4.3 + New Features

QGraphicsSvgItem control size

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgraphicssvgitesvg
5 Posts 3 Posters 1.7k Views 3 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by Joel Bodenmann
    #1

    Question
    What's the proper way of setting a "scale offset" or "resize offset" when working with QGraphicsSvgItem to control how big the rendered SVG is in scene coordinates? My source SVG has a size/viewbox of 0, 0, 24, 24 and therefore the rendered SVG is only 24x24 in size - but I'd like it to be larger.
    I started dicking around with retrieving the QSvgRenderer of the QGraphicsSvgItem using QGraphicsSvgItem::renderer() and then using QSvgRenderer::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() or QSvgRenderer::setSize().

    Background
    Currently I have a custom class named node that inherits from QGraphicsItem. 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 my node class and inside of node::paint() I use QIcon::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 a QIcon 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 my QIcon member and added a QGraphicsSvgItem child item to my node class.
    I managed to get everything working (as in: The SVG is successfully being rendered as part of my node 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 my node 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 the node::boundingRect() while also keeping the already working zoom scaling stuff.

    Unfortunately, I couldn't find a way of how to do this.

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I don't know either but what about nuking the viewport before loading the file ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Joel BodenmannJ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I don't know either but what about nuking the viewport before loading the file ?

        Joel BodenmannJ Offline
        Joel BodenmannJ Offline
        Joel Bodenmann
        wrote on last edited by
        #3

        @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?

        Industrial process automation software: https://simulton.com
        Embedded Graphics & GUI library: https://ugfx.io

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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 ?

            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