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. Qt 5.14 Updates to SVG Rendering
Forum Updated to NodeBB v4.3 + New Features

Qt 5.14 Updates to SVG Rendering

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 455 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.
  • Q Offline
    Q Offline
    Qt_User72653
    wrote on last edited by
    #1

    I have a function that creates a QImage from an SVG file; with the size parameter being the size of the QImage and the box parameter being the position and size of the rendered svg within that image:

    QImage fromSvg(const QString& path, const QSize& size,
        const QRect& box) {
      QSvgRenderer renderer(path);
      QImage image(size, QImage::Format_ARGB32);
      image.fill(QColor(0, 0, 0, 0));
      QPainter painter(&image);
      renderer.render(&painter, box);
      return image;
    }
    

    This was working fine until I updated to Qt 5.14, where it appears a change was made regarding how SVGs are rendered: https://github.com/qt/qtsvg/commit/c3ba57620c2c40d285004af2e1809e581e6bb7e7#diff-af44df228dc853c5da144ba0cb04f6a5

    I'm not much of a graphics expert; how can I update this to work with the new SVG rendering?

    KroMignonK 1 Reply Last reply
    0
    • Q Qt_User72653

      I have a function that creates a QImage from an SVG file; with the size parameter being the size of the QImage and the box parameter being the position and size of the rendered svg within that image:

      QImage fromSvg(const QString& path, const QSize& size,
          const QRect& box) {
        QSvgRenderer renderer(path);
        QImage image(size, QImage::Format_ARGB32);
        image.fill(QColor(0, 0, 0, 0));
        QPainter painter(&image);
        renderer.render(&painter, box);
        return image;
      }
      

      This was working fine until I updated to Qt 5.14, where it appears a change was made regarding how SVGs are rendered: https://github.com/qt/qtsvg/commit/c3ba57620c2c40d285004af2e1809e581e6bb7e7#diff-af44df228dc853c5da144ba0cb04f6a5

      I'm not much of a graphics expert; how can I update this to work with the new SVG rendering?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #5

      @Qt_User72653 I think you are facing with this issue: QTBUG-81259
      This should be revert in next coming release (Qt 5.14.1), which should be at January 21st.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

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

        Hi
        What is the effect of this change ?
        How does it look different from pre 5.14 ?

        Did you open the svg in say InkScape and look how the viewbox is ?
        (in inkscape its the page size/box)

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt_User72653
          wrote on last edited by Qt_User72653
          #3

          The majority of the time I'm trying to center the svg in the middle of the of the QImage, so pre 5.14 I could call it like so and expect the svg to be rendered in the middle of the image:

          fromSvg("file.svg", {20, 20}, {5, 5, 10, 10}); // image is 20x20, svg is rendered 10x10 at (5, 5).
          

          With 5.14, some images are rendered with the top left of the svg at the center of the QImage, and some svgs are rendered shifted up and to the left. I tried inputting various values to try to get a sense of how the new svg rendering works, but I couldn't find any consistency to it.

          I've looked at the svg files and they're all sized so the viewbox contains the image without any extra whitespace.

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qt_User72653
            wrote on last edited by
            #4

            I wound up creating a QIcon from an SVG then using the icon to generate a pixmap; I then draw that pixmap on top of the base image.

            https://stackoverflow.com/a/36936216/11234391

            1 Reply Last reply
            1
            • Q Qt_User72653

              I have a function that creates a QImage from an SVG file; with the size parameter being the size of the QImage and the box parameter being the position and size of the rendered svg within that image:

              QImage fromSvg(const QString& path, const QSize& size,
                  const QRect& box) {
                QSvgRenderer renderer(path);
                QImage image(size, QImage::Format_ARGB32);
                image.fill(QColor(0, 0, 0, 0));
                QPainter painter(&image);
                renderer.render(&painter, box);
                return image;
              }
              

              This was working fine until I updated to Qt 5.14, where it appears a change was made regarding how SVGs are rendered: https://github.com/qt/qtsvg/commit/c3ba57620c2c40d285004af2e1809e581e6bb7e7#diff-af44df228dc853c5da144ba0cb04f6a5

              I'm not much of a graphics expert; how can I update this to work with the new SVG rendering?

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #5

              @Qt_User72653 I think you are facing with this issue: QTBUG-81259
              This should be revert in next coming release (Qt 5.14.1), which should be at January 21st.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              5
              • Q Offline
                Q Offline
                Qt_User72653
                wrote on last edited by
                #6

                Perfect! Thank you.

                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