英文官方文档说明:
https://doc.qt.io/qt-5/qicon.html#themeName
英文官方文档摘抄部分,版权归原作者,笔者无版权,如下:
QIcon | fromTheme(const QString &name) |
QIcon | fromTheme(const QString &name, const QIcon &fallback) |
QIcon QIcon::fromTheme(const QString &name)
Returns the QIcon corresponding to name in the current icon theme.
The latest version of the freedesktop icon specification and naming specification can be obtained here:
- http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
- http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
To fetch an icon from the current icon theme:
QIcon undoicon = QIcon::fromTheme("edit-undo");
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().
Note: Qt will make use of GTK's icon-theme.cache if present to speed up the lookup. These caches can be generated using gtk-update-icon-cache: https://developer.gnome.org/gtk3/stable/gtk-update-icon-cache.html.
Note: If an icon can't be found in the current theme, then it will be searched in fallbackSearchPaths() as an unthemed icon.
This function was introduced in Qt 4.6.
See also themeName(), setThemeName(), themeSearchPaths(), and fallbackSearchPaths().
[static]
QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
This is an overloaded function.
Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead.
If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:
QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));
另外可以参考:【Qt】QIcon::fromTheme:从系统主题中获取图标