Donald Duck Donald Duck - 2 months ago 14
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

setIcon
method of
QWidget
. 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
  • 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.

Comments