Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why Qt ALWAYS draw my SVG image BLURRED and UGLY?
Forum Updated to NodeBB v4.3 + New Features

Why Qt ALWAYS draw my SVG image BLURRED and UGLY?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
15 Posts 6 Posters 12.4k Views 4 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.
  • GrecKoG Offline
    GrecKoG Offline
    GrecKo
    Qt Champions 2018
    wrote on last edited by
    #4

    How would you like it to be rendered?
    Your icon has too much detail to not be blurry at 12x12.

    SVG is not a magic tool managing to render any image with crisp sharp lines. That works when scaling up, scaling down is not as simple.

    Stretching the reasonning to the absurb, would you expect this svg to render a clean 4x4 icon? What about a 1x1 icon?

    KH-219DesignK 1 Reply Last reply
    2
    • jeanmilostJ Offline
      jeanmilostJ Offline
      jeanmilost
      wrote on last edited by
      #5

      @GrecKo said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

      Your icon has too much detail to not be blurry at 12x12.

      I'm not expecting Qt to operate a miracle, I just expect it to draw an image to an acceptable quality, or at least to allow me tweak the settings a bit to give me some latitude. For example, changing the smooth or antialiasing properties doesn't change nothing at all on my rendering, which is a shame in a such case. I'm aware that an icon may rarely be drawn perfectly in a such resolution, but I think that the quality should at least be a little better.

      Actually I get this rendering:
      844efb38-d31c-44a5-a75f-06072258ce8d-image.png

      What I expected is something like that (in the most perfect situation):
      Expected save icon.png

      or at least something like that (Chrome/Figma rendering):
      65c4719f-89ad-4e54-9305-9d81fb2759ed-image.png

      or like that (SVGMagic rendering):
      cdd00dd5-acf9-44c7-8087-4dfb1ec6d86a-image.png

      I can guarantee that the size of all the above renderings is always 12x12 pixels. As you can see, all the above renderings are clearer and more precise than the Qt one, even if not perfect. So it's theoricaly possible to get a readable icon even with a so small resolution. I'm not interested to draw a 4x4 or even 1x1 icon size, I just need to show an acceptable icon to my users :-)

      So my question remains: how can I improve the rendering of my SVG image? I would be very surprised if Qt didn't offer any options to improve this, right?

      1 Reply Last reply
      2
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #6
        import QtQuick 2.12
        import QtQuick.Window 2.12
        
        Window {
            visible: true
            width: 100
            height: 100
            title: qsTr("SVG Rendering")
        
            Row {
                spacing: 5
        
                Image {
                    width: 12
                    height: 12
                    source: "qrc:/icon_save.svg"
                    sourceSize: Qt.size(12, 12)
                    fillMode: Image.Tile//PreserveAspectFit
                    //smooth: true
                    smooth: false
                    antialiasing: false
                    //mipmap: false
                    opacity: 1.0
                    //cache:false
                    visible: true
                }
        
                Image {
                    width: 12
                    height: 12
                    source: "qrc:/icon_save.svg"
                    sourceSize: Qt.size(width*4,height*4)
                    fillMode: Image.PreserveAspectFit
                    //smooth: true
                    smooth: true
                    antialiasing: false
                    //mipmap: false
                    opacity: 1.0
                    //cache:false
                    visible: true
                }
            }
        }
        

        Turn smooth on, scale image to larger size so it renders in a larger space. Use preserveaspectfit to reduce to 12*12. Looks significantly crisper on my machine (Ubunut 18.04).

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        3
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by fcarney
          #7

          Also, can you go to 16x16? It is night and day at 12 versus 16.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1
          • MarkkyboyM Offline
            MarkkyboyM Offline
            Markkyboy
            wrote on last edited by
            #8

            Oh. . . . ?

            ||II||
            ô¿ô
            ( - )

            I better get my ass to Specsavers!!

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #9

              @Markkyboy I can't see anything up close anymore either. Don't feel bad.

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • KH-219DesignK Offline
                KH-219DesignK Offline
                KH-219Design
                wrote on last edited by
                #10

                @jeanmilost you might be running into the same thing that I "banged my head against" (figuratively) earlier this year.

                I, too, was shocked and dismayed at the SVG behavior I saw.

                Look at my happy face screenshots shown here: https://github.com/219-design/qt-qml-project-template-with-ci/pull/6

                If you are experiencing something like the "before" image shown at that link, and you want to instead see something like the "after" image, then my experience will be relevant to you.

                The SVG is giving "indications" to Qt to use an image buffer of the size of 12 pixels by 12 pixels. So Qt is rendering the SVG into a 12x12 bitmap, and then stretching that minuscule bitmap into a larger size, which makes it look pixelated and terrible.

                This has also been discussed on the bugtracker: https://bugreports.qt.io/browse/QTBUG-44863

                The key to getting the scaling that you desire is to properly set sourceSize. Once you learn that, it isn't too hard to manage.

                I went through several iterations on an Image-wrapper QML element that I now use as a drop-in replacement for Image throughout my QML code. The latest iteration is: https://github.com/219-design/qt-qml-project-template-with-ci/pull/32

                www.219design.com
                Software | Electrical | Mechanical | Product Design

                1 Reply Last reply
                4
                • GrecKoG GrecKo

                  How would you like it to be rendered?
                  Your icon has too much detail to not be blurry at 12x12.

                  SVG is not a magic tool managing to render any image with crisp sharp lines. That works when scaling up, scaling down is not as simple.

                  Stretching the reasonning to the absurb, would you expect this svg to render a clean 4x4 icon? What about a 1x1 icon?

                  KH-219DesignK Offline
                  KH-219DesignK Offline
                  KH-219Design
                  wrote on last edited by
                  #11

                  @GrecKo said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                  Stretching the reasonning to the absurb, would you expect this svg to render a clean 4x4 icon? What about a 1x1 icon?

                  Huh. Ok. I agree with @GrecKo .

                  I thought the problem was to do with scaling up (in which case setting a fixed sourceSize would clearly work against you).

                  If the problem is with scaling down, then my question would be:

                  • have you found any software (inkscape, perhaps?) that renders it crisply at 12x12?

                  If yes, and if you always want it displayed at exactly 12x12, then the path of least resistance is to export the crisp 12x12 version to a PNG and use that in the app.

                  www.219design.com
                  Software | Electrical | Mechanical | Product Design

                  1 Reply Last reply
                  2
                  • KH-219DesignK Offline
                    KH-219DesignK Offline
                    KH-219Design
                    wrote on last edited by
                    #12

                    There is some mention of a "90 DPI assumption" in the bug ticket https://bugreports.qt.io/browse/QTBUG-44863

                    @jeanmilost it might be worth subscribing to that ticket and possibly attaching your image.

                    www.219design.com
                    Software | Electrical | Mechanical | Product Design

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      SimonSchroeder
                      wrote on last edited by
                      #13

                      There is one more thing to consider: Do you adjust your SVG drawing to the corner of the pixel or the center? This does make a difference in Qt. I can't remember which is best to achieve pixel accuracy. Have look at this link https://doc.qt.io/qt-5/coordsys.html to learn about how Qt renders lines.

                      1 Reply Last reply
                      3
                      • jeanmilostJ Offline
                        jeanmilostJ Offline
                        jeanmilost
                        wrote on last edited by
                        #14

                        Thank to all for the replies.

                        @KH-219Design said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                        The key to getting the scaling that you desire is to properly set sourceSize. Once you learn that, it isn't too hard to manage.

                        Indeed configuring a higher source size (e.g 24x24 pixels) seems to improve notably the rendering quality, so I will play around that to find the best possible rendering for my image.

                        @KH-219Design said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                        I thought the problem was to do with scaling up (in which case setting a fixed sourceSize would clearly work against you).

                        I however noticed that letting Qt choose the source size, either by not configuring the sourceSizeproperty or by setting it to undefined, as suggested in the documentation, doesn't work well for such small renderings, unfortunately.

                        @KH-219Design said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                        @jeanmilost it might be worth subscribing to that ticket and possibly attaching your image.

                        Ok I'll check that

                        @SimonSchroeder said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                        Do you adjust your SVG drawing to the corner of the pixel or the center?

                        I sincerely don't know how to do that in qml. As I changed nothing about that, the rendering should be configured with the default values, but I don't know which they are. I assume that the pen is on the top and left corner of a pixel. Do you have information about how to configure that from an Image component in a qml file?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SimonSchroeder
                          wrote on last edited by
                          #15

                          @jeanmilost said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                          @SimonSchroeder said in Why Qt ALWAYS draw my SVG image BLURRED and UGLY?:

                          Do you adjust your SVG drawing to the corner of the pixel or the center?

                          I sincerely don't know how to do that in qml. As I changed nothing about that, the rendering should be configured with the default values, but I don't know which they are. I assume that the pen is on the top and left corner of a pixel. Do you have information about how to configure that from an Image component in a qml file?

                          What I meant is if the original SVG drawing is done on the center of the pixel or its corner. The only easy way I know to adjust this is to change the SVG. Just open up the SVG in a suitable editor and shift everything by half a pixel down and right.

                          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