Donald Duck
Donald Duck

Reputation: 8882

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?

Upvotes: 0

Views: 1374

Answers (3)

Gary Wang
Gary Wang

Reputation: 382

For linux/X11, maybe you are looking for QMimeDatabase::mimeTypesForFileName and QIcon::fromTheme.

Refer to https://stackoverflow.com/a/45739529/5785726 for a example

Upvotes: 0

frogatto
frogatto

Reputation: 29285

I think you're looking for QIcon::fromTheme method.

Example:

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().

Upvotes: 0

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

Upvotes: 3

Related Questions