Skip to content

fix: disable smooth scaling for DQuickDciIconImage to prevent icon blur#581

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix
Mar 5, 2026
Merged

fix: disable smooth scaling for DQuickDciIconImage to prevent icon blur#581
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Mar 5, 2026

Set smooth=false in constructor to match Qt Widgets rendering behavior.

在构造函数中设置 smooth=false 以匹配 Qt Widgets 渲染行为。

Log: 禁用 DQuickDciIconImage 平滑缩放
PMS: BUG-308655
Influence: 修复 QML 中 DCI 图标缩放时显示模糊的问题

Summary by Sourcery

Bug Fixes:

  • Prevent DQuickDciIconImage icons from appearing blurred during scaling in QML by turning off smooth scaling by default.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Sets DQuickDciIconImage to use non-smooth scaling by default to avoid blurred DCI icons in QML, aligning its behavior with Qt Widgets rendering.

Class diagram for updated DQuickDciIconImage smooth behavior

classDiagram
    class QQuickItem
    class QQuickImage {
        +implicitWidthChanged()
        +implicitHeightChanged()
        +setSmooth(bool smooth)
    }

    class DQuickDciIconImagePrivate {
        +QQuickImage* imageItem
    }

    class DQuickDciIconImage {
        +DQuickDciIconImage(QQuickItem* parent)
        +bool smooth
        +void setSmooth(bool smooth)
        +bool smoothChanged
    }

    DQuickDciIconImage --* DQuickDciIconImagePrivate : composition
    DQuickDciIconImagePrivate --> QQuickImage : has
    DQuickDciIconImage --|> QQuickItem

    %% Key behavioral change: default smooth is now false in constructor
Loading

File-Level Changes

Change Details Files
Default smooth scaling is disabled for DQuickDciIconImage to prevent icon blur.
  • Initialize the DQuickDciIconImage instance with smooth scaling turned off in its constructor
  • Keep existing signal connections so that future smooth property changes still propagate to the internal QQuickImage item
src/private/dquickdciiconimage.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new setSmooth(false) call happens before the smoothChanged signal is connected to d->imageItem, so the internal QQuickImage may keep its default smooth value; consider either connecting the signal before calling setSmooth, or explicitly initializing d->imageItem->setSmooth(false) to ensure both stay in sync.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `setSmooth(false)` call happens before the `smoothChanged` signal is connected to `d->imageItem`, so the internal `QQuickImage` may keep its default smooth value; consider either connecting the signal before calling `setSmooth`, or explicitly initializing `d->imageItem->setSmooth(false)` to ensure both stay in sync.

## Individual Comments

### Comment 1
<location path="src/private/dquickdciiconimage.cpp" line_range="211" />
<code_context>
     , DObject(*new DQuickDciIconImagePrivate(this))
 {
     D_D(DQuickDciIconImage);
+    setSmooth(false);
     connect(d->imageItem, &QQuickImage::implicitWidthChanged, this, [this, d]() { setImplicitWidth(d->imageItem->implicitWidth()); });
     connect(d->imageItem, &QQuickImage::implicitHeightChanged, this, [this, d]() { setImplicitHeight(d->imageItem->implicitHeight()); });
</code_context>
<issue_to_address>
**issue (bug_risk):** Align initial smooth state of the wrapper and underlying imageItem.

Because `setSmooth(false)` is called before the `smoothChanged` connection is set up, the initial value is not propagated to `d->imageItem`, so the wrapper reports `smooth == false` while the underlying `imageItem` likely remains `true`. Please either move `setSmooth(false)` after the `smoothChanged` connection or explicitly initialize both objects’ `smooth` state (e.g. also call `d->imageItem->setSmooth(false)`).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Set smooth=false in constructor to match Qt Widgets rendering behavior.

在构造函数中设置 smooth=false 以匹配 Qt Widgets 渲染行为。

Log: 禁用 DQuickDciIconImage 平滑缩放
PMS: BUG-308655
Influence: 修复 QML 中 DCI 图标缩放时显示模糊的问题
@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, re2zero

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这份代码变更包含两部分:CMake配置文件的版权年份更新和C++类DQuickDciIconImage构造函数中的逻辑修改。以下是详细的代码审查意见:

1. 文件:cmake/DtkBuildConfig.cmake

变更内容:更新了自动生成的头文件中的版权年份范围(2022 - 2026)。

  • 语法逻辑:正确。字符串拼接符合CMake语法。
  • 代码质量:良好。保持版权信息时效性是维护工作的一部分。
  • 代码性能:N/A(配置阶段执行)。
  • 代码安全:N/A。

2. 文件:src/private/dquickdciiconimage.cpp

变更内容:在 DQuickDciIconImage 构造函数中添加了 setSmooth(false)

DQuickDciIconImage::DQuickDciIconImage(QQuickItem *parent)
    : QQuickItem(parent)
    , DObject(*new DQuickDciIconImagePrivate(this))
{
    D_D(DQuickDciIconImage);
    setSmooth(false); // <--- 新增行
    // ... 后续连接信号槽的代码
}

详细审查意见:

1. 语法逻辑

  • 状态通过
  • 分析setSmoothQQuickItem (Qt Quick) 的公共方法,调用语法正确。在构造函数中初始化属性符合 C++ 惯例。

2. 代码质量与功能逻辑

  • 状态建议确认
  • 分析
    • 意图:将 smooth 属性设置为 false 意味着在缩放图标时使用最近邻插值,而不是双线性插值。这通常用于保持像素风格图标的锐利边缘,或者在某些高性能要求场景下减少 GPU 开销。
    • 潜在问题
      1. 默认值覆盖QQuickItemsmooth 属性默认值通常是 true。强制设为 false 会改变所有 DQuickDciIconImage 实例的渲染行为。如果 UI 设计意图是让图标平滑缩放(例如高分辨率屏幕下的矢量图标或位图),此修改会导致图标边缘出现锯齿,影响视觉体验。
      2. 属性绑定:代码中存在 connect(this, &DQuickDciIconImage::smoothChanged, d->imageItem, &QQuickImage::setSmooth);。这意味着外部可以通过设置 smooth 属性来改变行为。构造函数中的 setSmooth(false) 只是设定了初始状态。
    • 建议:请确认业务需求是否强制要求所有图标默认关闭平滑处理。如果是为了特定场景(如低性能设备),建议考虑通过 QML 属性或主题配置来控制默认值,而不是硬编码在 C++ 构造函数中。

3. 代码性能

  • 状态正面影响
  • 分析
    • 开启 smooth (双线性插值) 会消耗更多的 GPU 算力,尤其是在大量图标频繁缩放的场景下。
    • 设置为 false 可以略微提升渲染性能,减少 GPU 负载。对于图标这种通常不需要极高精度缩放(或者本身就是按像素设计的)的元素,这是一个合理的性能优化手段。

4. 代码安全

  • 状态安全
  • 分析:此修改仅涉及渲染属性设置,不涉及内存管理、输入验证或敏感数据处理,不存在安全风险。

总结与改进建议

该变更是安全的,语法正确,且能带来轻微的性能提升。主要风险在于视觉表现的变化

改进建议:

  1. 视觉回归测试:请务必在不同分辨率(尤其是 1080p 和 2K/4K)下检查图标显示效果。确认图标边缘是否出现不应有的锯齿或模糊。
  2. 文档化:建议在类的头文件或相关文档中注明 smooth 属性的默认行为已更改为 false,以便其他开发者或 UI 设计师知晓。
  3. 可选性(进阶建议)
    如果未来某些图标需要平滑处理,而另一些不需要,目前的架构(通过信号槽连接到 d->imageItem)已经支持动态修改。
    如果希望保持灵活性,可以考虑移除 C++ 中的硬编码 setSmooth(false),转而在 QML 层面(组件定义处)设置默认值,例如:
    DQuickDciIconImage {
        smooth: false // 在 QML 中统一设置默认值
    }
    这样如果不修改 C++ 源码,UI 开发者也能更容易地调整默认行为。但如果这是一个底层框架级的强制决策,目前的写法也是可以接受的。

@re2zero
Copy link
Contributor Author

re2zero commented Mar 5, 2026

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Mar 5, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 58d79ca into linuxdeepin:master Mar 5, 2026
18 of 21 checks passed
@re2zero re2zero deleted the bugfix branch March 5, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants