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

QIcon::fromTheme, fails on SVG with 'path + filename + extension'

    XMLWordPrintable

Details

    Description

      Qt 5.7.1 (qt-everywhere-opensource-src-5.7.1)

      availableSizes() always empty for SVG with filename & extension,
      but work for SVG with filename (without extension)

      qtbase-opensource-src-5.7.1+dfsg/src/gui/image/qicon.cpp:1209

      QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
      {
          QIcon icon = fromTheme(name);
      
          if (icon.isNull() || *icon.availableSizes().isEmpty()*)
              return fallback;
      
          return icon;
      }
      

      Probably it's happened because QSvgIconEngine has no "virtual_hook(int id, void *data)" unlike QPixmapIconEngine

      so, in next code (QIcon::addFile)
      use 'filename + extension' --> QSvgIconEngine and QIcon::fromTheme do not work as expected
      but if to variable fileName set only 'filename' --> QPixmapIconEngine --> SVG is Ok!

      This is easy reproduced with breakpoint at line 1041
      qt-everywhere-opensource-src-5.7.1/qtbase/src/gui//image/qicon.cpp

       QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State state)
      {
          if (fileName.isEmpty())
              return;
          detach();
          if (!d) {
      
              QFileInfo info(fileName);
              QIconEngine *engine = iconEngineFromSuffix(fileName, info.suffix());
      #ifndef QT_NO_MIMETYPE
              if (!engine)
                  engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix());
      #endif // !QT_NO_MIMETYPE
              d = new QIconPrivate;
              d->engine = engine ? engine : new QPixmapIconEngine;
          }
      
          d->engine->addFile(fileName, size, mode, state);
      
          // Check if a "@Nx" file exists and add it.
          QString atNxFileName = qt_findAtNxFile(fileName, qApp->devicePixelRatio());
          if (atNxFileName != fileName)
              d->engine->addFile(atNxFileName, size, mode, state);
      }
      

      At the same time icon.availableSizes().isEmpty() in QIcon::fromTheme has conflict with description:

      Qt 5.7.1, quote from src/gui/image/qiconengine.cpp:143
      \value AvailableSizesHook Allows to query the sizes of the contained pixmaps for pixmap-based engines. The \a data argument of the virtual_hook() function is a AvailableSizesArgument pointer that should be filled with icon sizes. Engines that work in terms of a scalable, vectorial format normally return an empty list.

      Checked under Kubuntu 17.04, test project https://github.com/chipmunk-sm/qicontest

      Affected to icon in .desktop file, so Dolphin and Application Menu do not show icon with full path and extensions.

      Attachments

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

        Activity

          People

            vgt Eirik Aavitsland
            chipmunk-sm sm chipmunk
            Votes:
            10 Vote for this issue
            Watchers:
            20 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes