Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/private/dquickdciiconimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ void DQuickDciIconImageItemPrivate::updatePlayer()

player->setPalette(palette);

// treeland下拿qApp的缩放不准确,初始化的时候尝试去更新一次缩放
updateDevicePixelRatio(1.0);

player->setDevicePixelRatio(devicePixelRatio);
}

Expand Down
28 changes: 19 additions & 9 deletions src/private/dquickiconimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ bool DQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio
return true;
}
#endif
qreal ratio = devicePixelRatio;
devicePixelRatio = targetDevicePixelRatio > 1.0 ? targetDevicePixelRatio : calculateDevicePixelRatio();

if (ratio != devicePixelRatio)
maybeUpdateUrl();

return true;
auto lastRatio = devicePixelRatio;
if (targetDevicePixelRatio > 1.0) {
devicePixelRatio = targetDevicePixelRatio;
} else {
devicePixelRatio = calculateDevicePixelRatio();
}
return lastRatio != devicePixelRatio;
}

void DQuickIconImagePrivate::updateBase64Image()
Expand Down Expand Up @@ -172,6 +172,13 @@ void DQuickIconImage::componentComplete()
D_D(DQuickIconImage);
// 初始化信号链接和url地址
d->init();

connect(this, &QQuickItem::windowChanged, this, [this](){
D_D(DQuickIconImage);
if (d->updateDevicePixelRatio(1.0)) {
d->maybeUpdateUrl();
}
});
}

/**
Expand Down Expand Up @@ -367,8 +374,11 @@ void DQuickIconImage::pixmapChange()
// QQuickImage中只会在设置了souceSize的前提下才会计算图片自身的缩放比例
// 此处强制确保图标的缩放比例正确
D_D(DQuickIconImage);
if (d->iconType == DQuickIconImagePrivate::ThemeIconName)
d->updateDevicePixelRatio(1.0);
if (d->iconType == DQuickIconImagePrivate::ThemeIconName) {
if (d->updateDevicePixelRatio(1.0)) {
d->maybeUpdateUrl();
}
}

QQuickImage::pixmapChange();

Expand Down
Loading