Viewer for Qt Icons:
- according to Icon Naming Specification
- MIME type database
- QStyle's standard pixmaps
- file pixmaps
- font icons
The Icon Theme Specification is in use in several desktops, including KDE and Gnome.
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
A standard pixmap is a pixmap that can follow some existing GUI style or guideline.
To fetch an icon from the current icon theme:
QIcon undoicon = QIcon::fromTheme("edit-undo");
The MIME type database is provided by the freedesktop.org shared-mime-info project. If the MIME type database cannot be found on the system, as is the case on most Windows, macOS, and iOS systems, Qt will use its own copy of it.
Shared Mime Info specification can be obtained here
To fetch an icon from the MIME type database:
QMimeDatabase db;
QMimeType mime = db.mimeTypeForName("application/pdf");
QIcon undoicon = QIcon::fromTheme(mime.iconName());
To fetch an standard pixmap from the current style from widget:
QIcon trashicon = style()->standardIcon(QStyle::SP_TrashIcon);
To fetch an icon from the file:
QPixmap pixmap(":/img/help.png")
QIcon icon(pixmap);
QFontIcon is a simple Qt class that allows you to create QIcon from a font file like font Awesome.
You just have to copy QFontIcon folder into your project. And add the following line in you project file.
include("QFontIcon/QFontIcon.pri")
You need a font file to use QFontIcon. You can for exemple download font Awesome and add it in your project as a resource file. Then use the class as follow:
Load first the font file only one time. In the main.cpp in the most of the case.
QFontIcon::addFont(":/fontawesome.ttf");
Then you can get icon from unicode:
QIcon icon = QFontIcon::icon(0xf501);