From 32014afc271a4a29a321dda8667b841a300570d5 Mon Sep 17 00:00:00 2001 From: Fan PengCheng Date: Mon, 26 Apr 2021 15:12:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A0=8F=E6=98=BE=E7=A4=BA=E5=9B=BE=E6=A0=87=E4=B8=BA=E9=BD=BF?= =?UTF-8?q?=E8=BD=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当获取图标为齿轮时,会在之后的半分钟内反复获取图标,这时,图标可能还没有放在指定的位置,所以显示异常,还有可能是qt内部的缓存机制导致的,第一次获取图标异常,后面不再尝试获取。 Log: 修复任务栏显示图标为齿轮的问题 Bug: https://pms.uniontech.com/zentao/bug-view-22246.html Change-Id: I281077c59906bcb1e387dc0cf9054cddb03f5ed2 --- frame/item/appitem.cpp | 12 ++++++++---- frame/util/themeappicon.cpp | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 8c7de56de..ae0433002 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -88,7 +88,7 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti m_updateIconGeometryTimer->setInterval(500); m_updateIconGeometryTimer->setSingleShot(true); - m_retryObtainIconTimer->setInterval(500); + m_retryObtainIconTimer->setInterval(3000); m_retryObtainIconTimer->setSingleShot(true); m_refershIconTimer->setInterval(1000); @@ -610,14 +610,18 @@ void AppItem::refreshIcon() } if (!m_iconValid) { - if (m_retryTimes < 5) { + if (m_retryTimes < 10) { m_retryTimes++; qDebug() << m_itemEntryInter->name() << "obtain app icon(" << icon << ")failed, retry times:" << m_retryTimes; + // Maybe the icon was installed after we loaded the caches. + // QIcon::setThemeSearchPaths will force Qt to re-check the gtk cache validity. + QIcon::setThemeSearchPaths(QIcon::themeSearchPaths()); + m_retryObtainIconTimer->start(); } else { - // 如果图标获取失败,没隔10秒刷新一次 + // 如果图标获取失败,一分钟后再自动刷新一次(如果还是显示异常,基本需要应用自身看下为什么了) if (!m_iconValid) - QTimer::singleShot(10 * 1000, this, [ = ] { m_retryObtainIconTimer->start(); }); + QTimer::singleShot(60 * 1000, this, &AppItem::refreshIcon); } update(); diff --git a/frame/util/themeappicon.cpp b/frame/util/themeappicon.cpp index 88eb8b3a4..78ea3b786 100644 --- a/frame/util/themeappicon.cpp +++ b/frame/util/themeappicon.cpp @@ -140,6 +140,9 @@ bool ThemeAppIcon::getIcon(QPixmap &pix, const QString iconName, const int size, } // 重新从主题中获取一次 + + // 如果此提交我们使用的qt版本已经包含,那就可以不需要reObtain的逻辑了 + // https://codereview.qt-project.org/c/qt/qtbase/+/343396 if (reObtain) icon = getIcon(iconName); else