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

QIcon:addFile with a SVG file hardcodes QIcon::Normal / QIcon::Off

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.9.0
    • GUI: Painting, SVG Support
    • None

    Description

      Testcase:

      QIcon icon;
      icon.addFile("file1.svg", {}, QIcon::Selected, QIcon::On);
      

      file1.svg gets actually added for the Normal/Off states , not for the specified one(s). Similarly,

      QIcon icon;
      icon.addFile("file1.svg", {}, QIcon::Normal, QIcon::On); 
      icon.addFile("file2.svg", {}, QIcon::Normal, QIcon::Off);
      

      will result in file2.svg provided when asked for a pixmap in Normal/On. This is for the same reason – file1.svg got actually added as Normal/Off and the second addFile "overwrote" the first one.

      I've investigated the issue a bit:

      1. QIcon::addFile calls iconEngineFromSuffix(fileName, suffix); here https://codebrowser.dev/qt6/qtbase/src/gui/image/qicon.cpp.html#1169
      2. iconEngineFromSuffix checks if any image plugin can load the file, it will find QSvgIconPlugin and call create(fileName) on it here https://codebrowser.dev/qt6/qtbase/src/gui/image/qicon.cpp.html#1118
      3. *QSvgIconPlugin::create outright ignores whatever mode one passed to addFile*, and hardcodes Normal/Off when loading the SVG here https://codebrowser.dev/qt6/qtsvg/src/plugins/iconengines/svgiconengine/main.cpp.html#_ZN14QSvgIconPlugin6createERK7QString

      Attachments

        Issue Links

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

          Activity

            People

              vgt Eirik Aavitsland
              peppe Giuseppe D'Angelo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes