Skip to content

fix: clear DCi icon state when setting other icon types#689

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
robertkill:master
Oct 16, 2025
Merged

fix: clear DCi icon state when setting other icon types#689
18202781743 merged 1 commit intolinuxdeepin:masterfrom
robertkill:master

Conversation

@robertkill
Copy link
Contributor

Fixed an issue where DCi icon state was not properly cleared when setting other icon types (QIcon, QStyle::StandardPixmap, DStyle::StandardPixmap). This could cause incorrect icon rendering when switching between different icon types.

The changes ensure that when setting a non-DCi icon, the DCi icon state is properly reset to avoid conflicts between different icon systems. When setting a DCi icon, the QAbstractButton icon is cleared to prevent interference.

Log: Fixed icon display issues when switching between different icon types

Influence:

  1. Test switching between QIcon, standard pixmap icons, and DCi icons
  2. Verify icons display correctly after type changes
  3. Test button appearance in different states (normal, hover, pressed)
  4. Check icon rendering consistency across different button types

fix: 设置其他图标类型时正确清除 DCi 图标状态

修复了在设置其他图标类型(QIcon、QStyle::StandardPixmap、
DStyle::StandardPixmap)时未正确清除 DCi 图标状态的问题。这可能导致在不
同图标类型之间切换时出现错误的图标渲染。

这些更改确保在设置非 DCi 图标时,DCi 图标状态被正确重置,以避免不同图
标系统之间的冲突。当设置 DCi 图标时,QAbstractButton 图标被清除以防止
干扰。

Log: 修复在不同图标类型之间切换时的图标显示问题

Influence:

  1. 测试在 QIcon、标准像素图标和 DCi 图标之间的切换
  2. 验证类型更改后图标正确显示
  3. 测试按钮在不同状态(正常、悬停、按下)下的外观
  4. 检查不同按钮类型之间的图标渲染一致性

PMS: BUG-337027

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: robertkill

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 added a commit to linuxdeepin/dtk6widget that referenced this pull request Oct 16, 2025
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#689
{
D_D(DIconButton);

QAbstractButton::setIcon(QIcon());
Copy link
Contributor

Choose a reason for hiding this comment

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

这种重置放在真实赋值后面会不会更好,
重置可能会触发Icon重绘,这时可能先是一个空的,之后再绘制正确的icon,
可能导致闪烁,

Fixed an issue where DCi icon state was not properly cleared
when setting other icon types (QIcon, QStyle::StandardPixmap,
DStyle::StandardPixmap). This could cause incorrect icon rendering when
switching between different icon types.

The changes ensure that when setting a non-DCi icon, the DCi icon state
is properly reset to avoid conflicts between different icon systems.
When setting a DCi icon, the QAbstractButton icon is cleared to prevent
interference.

Log: Fixed icon display issues when switching between different icon
types

Influence:
1. Test switching between QIcon, standard pixmap icons, and DCi icons
2. Verify icons display correctly after type changes
3. Test button appearance in different states (normal, hover, pressed)
4. Check icon rendering consistency across different button types

fix: 设置其他图标类型时正确清除 DCi 图标状态

修复了在设置其他图标类型(QIcon、QStyle::StandardPixmap、
DStyle::StandardPixmap)时未正确清除 DCi 图标状态的问题。这可能导致在不
同图标类型之间切换时出现错误的图标渲染。

这些更改确保在设置非 DCi 图标时,DCi 图标状态被正确重置,以避免不同图
标系统之间的冲突。当设置 DCi 图标时,QAbstractButton 图标被清除以防止
干扰。

Log: 修复在不同图标类型之间切换时的图标显示问题

Influence:
1. 测试在 QIcon、标准像素图标和 DCi 图标之间的切换
2. 验证类型更改后图标正确显示
3. 测试按钮在不同状态(正常、悬停、按下)下的外观
4. 检查不同按钮类型之间的图标渲染一致性

PMS: BUG-337027
deepin-ci-robot added a commit to linuxdeepin/dtk6widget that referenced this pull request Oct 16, 2025
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#689
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这段代码是关于两个类(DButtonBoxButton 和 DIconButton)的图标设置相关功能的修改。我来分析一下代码的改进点:

语法逻辑

  1. 代码逻辑基本正确,两个类在设置不同类型的图标时都遵循了相似的模式。
  2. 在设置图标时,都会重置 dciIcon 对象,这是一个好的实践,确保状态的一致性。

代码质量

  1. 代码格式规范,缩进和空行使用得当。
  2. 两个类的实现保持了高度的一致性,这有利于代码维护。
  3. 使用了 D_D 宏来访问私有对象,这是项目中一贯的风格。

代码性能

  1. 在设置 DDciIcon 时,会调用 QAbstractButton::setIcon(QIcon()),这可能会触发不必要的重绘。可以考虑只在必要时才调用 update() 和 updateGeometry()。
  2. 在 DIconButton::setIcon(const DDciIcon &icon) 中,每次都会调用 update() 和 updateGeometry(),这可能不是必须的,可以添加条件判断。

代码安全

  1. 代码中没有明显的安全隐患。
  2. 对象的状态管理得当,在设置新图标前会重置相关的状态变量。

改进建议

  1. 对于 DIconButton::setIcon(const DDciIcon &icon) 中的 update() 和 updateGeometry() 调用,可以添加条件判断,避免不必要的更新:
if (d->dciIcon != icon) {
    d->dciIcon = icon;
    d->iconType = -1;
    QAbstractButton::setIcon(QIcon());
    this->update();
    this->updateGeometry();
}
  1. 考虑添加一个私有方法来处理图标更新的通用逻辑,减少代码重复:
void DIconButton::updateIcon(const QIcon &icon, int type)
{
    D_D(DIconButton);
    d->dciIcon = DDciIcon();
    d->iconType = type;
    QAbstractButton::setIcon(icon);
    this->update();
    this->updateGeometry();
}
  1. 可以考虑添加对传入图标的验证,确保图标有效后再进行设置:
void DIconButton::setIcon(const QIcon &icon)
{
    if (icon.isNull()) {
        qWarning() << "Attempt to set null icon";
        return;
    }
    D_D(DIconButton);
    d->dciIcon = DDciIcon();
    d->iconType = -1;
    QAbstractButton::setIcon(icon);
}
  1. 对于 DButtonBoxButton 和 DIconButton,可以考虑添加一个标志位来跟踪是否需要更新界面,避免在不需要时调用 update() 和 updateGeometry()。

  2. 考虑添加文档注释,说明各个方法的功能和使用注意事项,提高代码的可读性和可维护性。

总的来说,这段代码的实现是合理的,但还有一些可以优化的地方,特别是在性能和代码复用方面。

@18202781743 18202781743 merged commit 13e0778 into linuxdeepin:master Oct 16, 2025
22 of 23 checks passed
18202781743 pushed a commit to linuxdeepin/dtk6widget that referenced this pull request Oct 16, 2025
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#689
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