Donald Duck Donald Duck - 4 months ago 38
C++ Question

Use a system icon in the setIcon method of QWidget

I would like cross-platform a way to get a system icon, for example the folder icon folder icon in the

method of
. Something like this:

QWidget *myWidget = new QWidget;
myWidget->setIcon(/*something to get a system icon*/);

Is this possible? If it is, how to do it?

  • Use QFileIconProvider::icon(IconType) to get an icon of a particular kind, from a small selection of types.

    In your particular case, you'd want icon(QFileIconProvider::Folder).

  • Use QFileIconProvider::icon(const QFileInfo &) to get an icon for a particular directory entry.

  • Use QIcon::fromTheme(const QString &, const QIcon & = QIcon()) to get a theme icon on Linux/X11.