From e1175bdec234e2c42696a3e18206f9b2fe481020 Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Mon, 26 Apr 2021 19:10:28 +0800 Subject: [PATCH] [Fix] Sometimes file icon wouldn't be displayed correctly if name of the file contians special symbols. --- src/control/home-page-item.cpp | 2 +- src/control/search-detail-view.cpp | 2 +- src/model/search-item.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/control/home-page-item.cpp b/src/control/home-page-item.cpp index 8dd5440..997fd0a 100644 --- a/src/control/home-page-item.cpp +++ b/src/control/home-page-item.cpp @@ -77,7 +77,7 @@ void HomePageItem::setupUi(const int& type, const QString& path) { case SearchListView::ResType::Content: case SearchListView::ResType::Dir : case SearchListView::ResType::File : { - icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); + icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString()); // m_namelabel->setText(FileUtils::getFileName(path)); QFontMetrics fontMetrics = m_namelabel->fontMetrics(); QString name = FileUtils::getFileName(path); diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 8b840e3..c15f0df 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -351,7 +351,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) { case SearchListView::ResType::Content: case SearchListView::ResType::Dir : case SearchListView::ResType::File : { - QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); + QIcon icon = FileUtils::getFileIcon(QUrl::fromLocalFile(path).toString()); m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96)))); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); QString wholeName = FileUtils::getFileName(path); diff --git a/src/model/search-item.cpp b/src/model/search-item.cpp index 37a2948..57de2a7 100644 --- a/src/model/search-item.cpp +++ b/src/model/search-item.cpp @@ -42,7 +42,8 @@ QIcon SearchItem::getIcon(int index) { case Contents: case Dirs : case Files : //文件,返回文件图标 - return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index))); +// return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index))); + return FileUtils::getFileIcon(QUrl::fromLocalFile(m_pathlist.at(index)).toString()); case Apps : {//应用,返回应用图标 // return FileUtils::getAppIcon(m_pathlist.at(index)); if(m_app_pathlist.length() > index && m_app_pathlist.at(index) == "") { //未安装,存储的是图标路径 @@ -115,7 +116,7 @@ QIcon SearchItem::getBestIcon(const int &index) { return FileUtils::getSettingIcon(m_pathlist.at(index), false); } default: { - return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index))); + return FileUtils::getFileIcon(QUrl::fromLocalFile(m_pathlist.at(index)).toString()); } } }