Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-96203

QML SVG, PDF & QQuickImageProvider rendering ignores Screen.devicePixelRatio

    XMLWordPrintable

Details

    • All

    Description

      QML Images always render SVG, PDF and QQuickImageProvider with a device-pixel-ratio of 1.0, regardless of the actual screen dpi unless sourceSize is set.

      This is always pixellated on Hi-DPI screens:

      import QtQuick 2.15
      
      Image {
        source: "icon_extensions.svg"
      }
      

      This is causing serious difficulty in making QML-based applications support hi-dpi and mixed-dpi platforms, such as Windows 10/11, as sourceSize cannot be set without also explicitly setting the Image height and width.

      So far the closest thing I've found to a workaround is to hard-code the device-independent-pixel size of the (eg) SVG into the QML, like so:

      import QtQuick 2.15
      
      Image {
        source: "icon_extensions.svg"
        // Manually looked up from the SVG
        sourceSize.width: 24
        sourceSize.height: 24
      }
      

      This is not generally acceptable, as it means every single Image item has to be set to an explicit size that must match the SVG it loads.
      I have not yet found any QML API that exposes the 'original native' size of an Image source.

      This does not appear to be related to QTBUG-94855.

      The issue seems to be that qquickimagebase explicitly sets a device pixel ratio of 1.0, unless the sourceSize has been overridden or there is an "@2x" version of a bitmap

          if (loadOptions & HandleDPR) {
              const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
              d->devicePixelRatio = 1.0;
              bool updatedDevicePixelRatio = false;
              if (d->sourcesize.isValid())  // BUG!! This check prevents SVG, PDF and QQuickImageProviders from rendering at high quality
                  updatedDevicePixelRatio = d->updateDevicePixelRatio(targetDevicePixelRatio);
      
              if (!updatedDevicePixelRatio) {
                  // (possible) local file: loadUrl and d->devicePixelRatio will be modified if
                  // an "@2x" file is found.
                  resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
              }
          }

      Attachments

        1. icon_extensions.svg
          0.4 kB
        2. image-2022-02-11-18-59-44-823.png
          image-2022-02-11-18-59-44-823.png
          7 kB
        3. QtBug.zip
          3 kB

        Issue Links

          Activity

            People

              vgt Eirik Aavitsland
              rthompson Richard Thompson
              Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated: