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

Rich Text, html still fail to find high-dpi images

XMLWordPrintable

    • 52ce0c177e80c2d5b70b38d429abb3689b3da51e (qt/qtbase/dev) 760df7256588e76d082ea959399af36d7ba80a86 (qt/qtbase/5.15)

      Rich text can't handle @2x images:
      Given

      foo.png
      foo@2x.png
      

      Then

       <img src="foo.png">
      

      Will fail to load the hi-dpi version

      The reason is in /src/gui/text/qtextimagehandler.cpp
      The function to find the hi-dpi image fails to assign the result to the output QUrl variable

      static QString resolveFileName(QString fileName, QUrl *url, qreal targetDevicePixelRatio,
                                     qreal *sourceDevicePixelRatio)
      {
          ...
          if (targetDevicePixelRatio <= 1.0)
              return fileName;
      
          // try to find a Nx version
          return qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
      }
      

      Notice, the url is not updated.

      A simple fix can be

      const QString res = qt_findAtNxFile(fileName, targetDevicePixelRatio, sourceDevicePixelRatio);
        if(res != fileName)
          *url = QUrl(res);
        return res;
      

      Related bug QTBUG-46777

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            andysh Andy Shaw
            mnaydenov Mihail Naydenov
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes