So far, I get icon file like this
{
const QString ext
=info.
suffix().
toLower();
if (ext == "pdf") {
icon
=QIcon::fromTheme("application-pdf");
} else if (ext.startsWith("doc")) {
icon
=QIcon::fromTheme("application-msword");
} else if (ext=="zip" ||
ext=="gz" ||
ext=="bz2" ) {
icon
=QIcon::fromTheme("application-x-archive");
} else if (ext=="png" ||
ext=="jpg" ||
ext=="gif" ||
ext=="svg" ||
ext=="bmp") {
icon
=QIcon::fromTheme("image-x-generic");
} else {
QProxyStyle s;
icon
=s.
standardIcon (QStyle::SP_FileIcon);
}
return icon;
}
QIcon Olongia::fileIcon(const QString &filename)
{
QFileInfo info(filename);
const QString ext=info.suffix().toLower();
QIcon icon;
if (ext == "pdf") {
icon=QIcon::fromTheme("application-pdf");
} else if (ext.startsWith("doc")) {
icon=QIcon::fromTheme("application-msword");
} else if (ext=="zip" ||
ext=="gz" ||
ext=="bz2" ) {
icon=QIcon::fromTheme("application-x-archive");
} else if (ext=="png" ||
ext=="jpg" ||
ext=="gif" ||
ext=="svg" ||
ext=="bmp") {
icon=QIcon::fromTheme("image-x-generic");
} else {
QProxyStyle s;
icon=s.standardIcon (QStyle::SP_FileIcon);
}
return icon;
}
To copy to clipboard, switch view to plain text mode
I think that is not efficient, and after read qtdoc I get new trick like this
QIcon icon
=ip.
icon(info
);
QFileInfo info(filename);
QFileIconProvider ip;
QIcon icon=ip.icon(info);
To copy to clipboard, switch view to plain text mode
But, that code only working if file is exists in local system. And I need get file type icon for file not exists in local system ? Like QFtp example, only get the filename and show in the TreeViewWidget ?
Thank's before and sorry about my suck english
Bookmarks