Skip to content

feat: add support for custom line edit icon margin#696

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:fix
Oct 28, 2025
Merged

feat: add support for custom line edit icon margin#696
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:fix

Conversation

@18202781743
Copy link
Contributor

Added PM_LineEditIconMargin pixel metric handling to support custom
icon margins in line edit widgets. The implementation checks for a
"_d_dtk_lineeditIconMargin" property on the widget and returns the
custom margin value if valid. This allows applications to specify
precise icon spacing in line edit fields for better UI customization and
visual consistency.

Influence:

  1. Test line edit widgets with custom icon margin property set
  2. Verify default behavior when no custom margin is specified
  3. Test with various valid margin values (positive integers)
  4. Verify behavior with invalid margin values (negative numbers, invalid
    types)
  5. Check UI layout consistency with custom icon margins applied

feat: 添加支持自定义行编辑图标边距

添加了 PM_LineEditIconMargin 像素度量处理,以支持在行编辑部件中自定义图
标边距。该实现检查部件上的 "_d_dtk_lineeditIconMargin" 属性,如果有效则
返回自定义边距值。这允许应用程序为行编辑字段指定精确的图标间距,以实现更
好的 UI 定制和视觉一致性。

Influence:

  1. 测试设置了自定义图标边距属性的行编辑部件
  2. 验证未指定自定义边距时的默认行为
  3. 使用各种有效边距值(正整数)进行测试
  4. 验证无效边距值(负数、无效类型)时的行为
  5. 检查应用自定义图标边距后的 UI 布局一致性

PMS: BUG-334965

@18202781743 18202781743 requested review from BLumia and mhduiy October 24, 2025 06:03
deepin-ci-robot added a commit to linuxdeepin/dtk6widget that referenced this pull request Oct 24, 2025
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#696
deepin-ci-robot added a commit to linuxdeepin/dtk6widget that referenced this pull request Oct 24, 2025
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#696
deepin-ci-robot added a commit to linuxdeepin/dtk6widget that referenced this pull request Oct 24, 2025
Synchronize source files from linuxdeepin/dtkwidget.

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Added PM_LineEditIconMargin pixel metric handling to support custom
icon margins in line edit widgets. The implementation checks for a
"_d_dtk_lineeditIconMargin" property on the widget and returns the
custom margin value if valid. This allows applications to specify
precise icon spacing in line edit fields for better UI customization and
visual consistency.

Influence:
1. Test line edit widgets with custom icon margin property set
2. Verify default behavior when no custom margin is specified
3. Test with various valid margin values (positive integers)
4. Verify behavior with invalid margin values (negative numbers, invalid
types)
5. Check UI layout consistency with custom icon margins applied

feat: 添加支持自定义行编辑图标边距

添加了 PM_LineEditIconMargin 像素度量处理,以支持在行编辑部件中自定义图
标边距。该实现检查部件上的 "_d_dtk_lineeditIconMargin" 属性,如果有效则
返回自定义边距值。这允许应用程序为行编辑字段指定精确的图标间距,以实现更
好的 UI 定制和视觉一致性。

Influence:
1. 测试设置了自定义图标边距属性的行编辑部件
2. 验证未指定自定义边距时的默认行为
3. 使用各种有效边距值(正整数)进行测试
4. 验证无效边距值(负数、无效类型)时的行为
5. 检查应用自定义图标边距后的 UI 布局一致性

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

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

deepin pr auto review

我来对这个diff进行审查:

  1. 代码语法和逻辑:
  • 语法正确,符合C++和Qt的规范
  • 逻辑清晰,添加了一个新的静态方法setLineEditIconMargin来设置行编辑框图标的边距
  • 在pixelMetric方法中正确处理了PM_LineEditIconMargin的情况
  1. 代码质量:
  • 命名规范:使用了驼峰命名法,符合Qt的命名规范
  • 注释:添加了关于Qt版本和补丁的说明,有助于理解代码的上下文
  • 代码结构:新增功能与现有代码结构保持一致
  1. 代码性能:
  • 使用了Qt的属性系统,性能良好
  • 在pixelMetric中的检查逻辑高效,直接返回属性值或使用默认值
  1. 代码安全:
  • 添加了margin值的合法性检查(margin >= 0)
  • 使用QVariant::toInt()并检查返回值,确保类型转换的安全性
  • 使用Q_FALLTHROUGH()宏明确表示代码的意图,避免编译器警告

改进建议:

  1. 在头文件中添加更详细的文档注释,说明这个功能的具体用途和参数含义:
/**
 * @brief 设置行编辑框图标的边距
 * @param object 目标QObject对象
 * @param margin 图标边距值,必须为非负数
 */
static void setLineEditIconMargin(QObject *object, int margin);
  1. 可以考虑在setLineEditIconMargin方法中添加参数验证:
void DStyle::setLineEditIconMargin(QObject *object, int margin)
{
    if (!object || margin < 0) {
        return;
    }
    object->setProperty("_d_dtk_lineeditIconMargin", margin);
}
  1. 考虑为这个功能添加一个对应的getter方法,以保持API的完整性:
static int lineEditIconMargin(const QObject *object);
  1. 可以考虑将属性名定义为常量,以提高代码的可维护性:
static const char* const LINE_EDIT_ICON_MARGIN_PROPERTY = "_d_dtk_lineeditIconMargin";
  1. 在pixelMetric方法中,可以考虑将margin的默认值定义为常量,便于维护:
static const int DEFAULT_LINE_EDIT_ICON_MARGIN = 0; // 或其他合适的默认值

这些改进建议主要是为了提高代码的可维护性、完整性和健壮性,但现有的实现已经基本满足功能需求。

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

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