Getting a file icon solely from a given MIME-type (no file itself) in Qt

412 views Asked by At

Ok, I know about the class QFileIconProvider. I also know about QMimeType (and QMimeDatabase). But I am surprised that I cannot find a simple connection between the two.

So what I need is to get an icon used by the operating system for a given type of files. Normally, this is done like this:

QIcon icon = QFileIconProvider().icon(QFileInfo("/path/to/some.file"));

But what if I want to get an icon without reference to a particular file, just for a given MIME type? Say, my application uses attached files and syncs across multiple devices; on some devices the attached file might be absent, but I know the MIME type of that file, so I still want my app to show the proper file icon, using only the MIME type info.

As a temporary solution, I found that if I pass a non-existing file to QFileInfo in the code string above, it does retrieve a correct icon (obviously, purely from the extension of that non-existing file), at least in Linux. But this method is not documented, and there is no guarantee it will always work.

So I need something that could work as the non-existing method QFileIconProvider().icon(QMimeType &).

0

There are 0 answers