[Interest] QIcon::fromTheme on OS X

René J.V. Bertin rjvbertin at gmail.com
Wed Dec 23 17:07:48 CET 2015


Hello,

I am sparring with QIcon::fromTheme() on OS X, and have the feeling I'm missing something from the documentation.

From

"Note: By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName()."

I understand that even with the native OS X platform theme, all I would have to do is ensure that QIcon::themeSearchPaths() returns a list with XDG-compliant icon themes, and QIcon::themeName() a ditto icon theme name.

I think I am replying to both conditions, adding

        qDebug() << Q_FUNC_INFO << "themeSearchPaths=" << themeSearchPaths() << "themeName=" << themeName();

to the actual lookup-part of QIcon::fromTheme() I get the output

static QIcon QIcon::fromTheme(const QString &, const QIcon &) themeSearchPaths= ("/opt/local/share/icons", "/opt/local/share/pixmaps", ":/icons") themeName= "hicolor"

Evidently I have the hicolor theme in /opt/local/share/icons, and indeed when I launch applications using the XCB QPA plugin or using the KDE platform theme, I'm getting the expected icons, e.g.

hasUserTheme= false engine= 0x7fe58bf583a0 name "dialog-ok" -> QIcon("dialog-ok",availableSizes[normal,Off]=(QSize(16, 16), QSize(22, 22), QSize(32, 32), QSize(48, 48), QSize(64, 64), QSize(128, 128), QSize(256, 256)),cacheKey=0x100000000)

However, using just the native OS X theme I'm seeing this:

hasUserTheme= false engine= 0x7fb5b9e3c880 name "dialog-ok" -> QIcon(availableSizes[normal,Off]=(),cacheKey=0x100000000)
hasUserTheme= false engine= 0x7fb5b9f05b40 name "dialog-cancel" -> QIcon(availableSizes[normal,Off]=(),cacheKey=0x200000000)
hasUserTheme= false engine= 0x7fb5b9c71c20 name "user-trash" -> QIcon(availableSizes[normal,Off]=(),cacheKey=0x700000000)

It looks like a bit of required functionality isn't loaded or is cut out of the loop with the OS X platform theme, but that's not what the documentation suggests.

Alternatively: the documentation also mentions a "guaranteed fallback for platforms that do not support theme icons", e.g. "edit-undo" == ":/undo.png". Is there a lookup function somewhere that maps all known/supported XDG icon names to that fallback naming scheme?

Thanks,
René



More information about the Interest mailing list