Donald Duck Donald Duck - 1 year ago 93
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?

Answer Source
  • 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download