mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-13 20:32:05 +08:00
update:更正之前新增的加载默认图标代码,
This commit is contained in:
@@ -90,26 +90,11 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
|
||||
// 调整图标位置,为复选框留出空间
|
||||
QRect iconRect(rect.left() + 40, rect.top() + (rect.height() - iconSize) / 2, iconSize, iconSize);
|
||||
|
||||
// 检查图标路径是否存在,如果不存在则使用默认图标
|
||||
QString finalIconPath = iconPath;
|
||||
qDebug() << "原始图标路径:" << iconPath;
|
||||
if (iconPath.isEmpty() || !QFile::exists(iconPath)) {
|
||||
finalIconPath = ":/resources/default_icon.png";
|
||||
qDebug() << "图标文件不存在,使用默认图标:" << finalIconPath;
|
||||
} else {
|
||||
qDebug() << "使用图标文件:" << finalIconPath;
|
||||
}
|
||||
|
||||
// 额外检查资源文件是否存在
|
||||
if (finalIconPath.startsWith(":/") && QIcon(finalIconPath).isNull()) {
|
||||
qDebug() << "资源图标无法加载,使用备用默认图标";
|
||||
finalIconPath = ":/resources/default_icon.png";
|
||||
}
|
||||
|
||||
// 如果是忽略状态,绘制灰色图标
|
||||
if (isIgnored) {
|
||||
// 创建灰度效果
|
||||
QPixmap originalPixmap = QIcon(finalIconPath).pixmap(iconSize, iconSize);
|
||||
QPixmap originalPixmap = QIcon(iconPath).pixmap(iconSize, iconSize);
|
||||
QPixmap grayPixmap(originalPixmap.size());
|
||||
grayPixmap.fill(Qt::transparent);
|
||||
QPainter grayPainter(&grayPixmap);
|
||||
@@ -118,7 +103,7 @@ void AppDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, c
|
||||
grayPainter.end();
|
||||
painter->drawPixmap(iconRect, grayPixmap);
|
||||
} else {
|
||||
QIcon(finalIconPath).paint(painter, iconRect);
|
||||
QIcon(iconPath).paint(painter, iconRect);
|
||||
}
|
||||
|
||||
int textX = iconRect.right() + margin;
|
||||
|
||||
Reference in New Issue
Block a user