Skip to content

fix: keep placeholder within text margins (DLineEditEx) - #76

Draft
mhduiy wants to merge 1 commit into
masterfrom
agent/bot/fc82379b
Draft

fix: keep placeholder within text margins (DLineEditEx)#76
mhduiy wants to merge 1 commit into
masterfrom
agent/bot/fc82379b

Conversation

@mhduiy

@mhduiy mhduiy commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

修复:锁屏/登录密码框占位符省略后与功能图标重叠

问题

锁屏/登录界面在「焦点态 + 空文本 + 居中 placeholder」分支手动重绘 placeholder 时,省略与绘制使用的是 DLineEditEx 整框 rect() 宽度,未扣除内嵌 QLineEdittextMargins()(即大写、显示密码、认证状态、密码提示等图标的避让区),导致长错误/提示文案省略后仍横跨整框、与左右功能图标重叠。

改动

  • 仓库:dde-session-shell
  • 文件:src/widgets/dlineeditex.cppDLineEditEx::paintEvent()
  • 将 placeholder 的省略(elidedText 宽度参数)与绘制(drawText 目标矩形)从整框 rect() 约束到「扣除内嵌 QLineEdittextMargins() 后的文本可用矩形」内
  • 通过 le->mapTo(this, QPoint(0,0)) 将内嵌 QLineEdit(子控件)坐标映射到 DLineEditEx(QFrame,QPainter(this) 绘制坐标系),避免父子控件坐标换算导致省略宽度偏差
  • tooltip 逻辑保持不变;不涉及后端 DBus / deepin-authenticate / DTK 控件 / DConfig / 翻译 / QSS

验证

  • 语法/类型检查:g++ -std=c++17 -fsyntax-only(Qt6 / dtk6widget 头文件路径)通过,仅余一处与本次改动无关的既有 QGuiApplication::fontChanged 弃用告警
  • 代码审核:已通过(坐标映射正确性、textMargins 读取时机、未设 textMargins 场景回归、Qt6 路径)
  • 编译构建:基于 master 重建并构建通过,主包 dde-session-shell_5.6.12.1_amd64.deb 已产出
  • 运行时 GUI 自测:英文 locale 或调大字号/缩放下、设较长密码提示、锁屏/登录输错密码后清空密码框,确认 placeholder 省略后止于左右图标内侧、不再重叠;中文短文案回归正常(待人工确认)

关联

说明

本次 PR 仅含业务修复 src/widgets/dlineeditex.cpp;打包适配改动(debian/*)为本地构建所需,未纳入本 PR。PR 保持 draft/待审核状态,请勿合并。

Summary by Sourcery

Bug Fixes:

  • Ensure centered placeholders in lock/login password fields are elided and drawn within the usable text rectangle, avoiding overlap with left/right functional icons.

1. Elide and draw placeholder within QLineEdit rect minus textMargins
2. Map QLineEdit to DLineEditEx via le->mapTo(this, QPoint(0,0))
3. Fixes overlap with caps-lock, password and hint icons on lock/login

Log: Fixed password prompt overlapping icons on lock and login screens

Influence:
1. Lock/login: long password hint elided, not overlapping the icons
2. caps-lock/show-password/hint icons stay clear of placeholder
3. Regression: short Chinese placeholder centered, no anomaly
4. Shared DLineEditEx inputs (account/single/ukey) show placeholder ok

fix: 将占位符约束在文本边距内

1. 将 DLineEditEx::paintEvent() 中占位符的省略与绘制约束到扣除内嵌
   QLineEdit 的 textMargins() 后的文本可用矩形内,不再使用整框 rect()
2. 通过 le->mapTo(this, QPoint(0,0)) 将内嵌 QLineEdit 坐标映射到
   DLineEditEx 绘制坐标系,避免父子控件坐标换算导致省略宽度偏差
3. 修复锁屏/登录界面长错误或提示占位符与大写、显示密码、密码提示
   图标重叠的问题

Log: 修复锁屏/登录界面密码提示文案省略后仍与图标重叠的问题

Influence:
1. 锁屏/登录界面:英文 locale 或调大字号/缩放下,设较长密码提示,
   输错密码后清空密码框,确认占位符省略后止于左右图标内侧、不再重叠
2. 确认大写、显示密码、密码提示图标与占位符区域保持独立
3. 回归:中文短文案占位符居中显示正常、无视觉异常
4. 共用 DLineEditEx 的账号/单因子/ukey 输入框占位符显示正常

PMS: BUG-351887
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

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

@sourcery-ai

sourcery-ai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts DLineEditEx placeholder rendering so that elided placeholder text is constrained to the inner QLineEdit’s text area, preventing overlap with left/right icons, while keeping existing tooltip behavior intact.

Sequence diagram for updated placeholder painting in DLineEditEx::paintEvent

sequenceDiagram
    participant DLineEditEx
    participant QLineEdit as lineEdit
    participant QPainter as pa
    participant QFontMetrics as fm

    DLineEditEx->>QPainter: QPainter(this)
    DLineEditEx->>QFontMetrics: QFontMetrics(pa.font())
    DLineEditEx->>QLineEdit: lineEdit()
    DLineEditEx->>QLineEdit: placeholderText()
    QLineEdit-->>DLineEditEx: placeholderText
    DLineEditEx->>QLineEdit: textMargins()
    QLineEdit-->>DLineEditEx: tm
    DLineEditEx->>QLineEdit: mapTo(this, QPoint(0,0))
    QLineEdit-->>DLineEditEx: topLeftInParent
    DLineEditEx->>DLineEditEx: build lineEditRect(topLeftInParent, le->size())
    DLineEditEx->>DLineEditEx: build textRect(lineEditRect.adjusted(tm.left(), tm.top(), -tm.right(), -tm.bottom()))
    DLineEditEx->>QFontMetrics: elidedText(placeholderText, Qt::ElideRight, textRect.width())
    QFontMetrics-->>DLineEditEx: elidedText
    DLineEditEx->>QPainter: drawText(textRect, Qt::AlignCenter | Qt::TextSingleLine, elidedText)
Loading

File-Level Changes

Change Details Files
Constrain placeholder elision and drawing to the QLineEdit text area accounting for textMargins and parent-child coordinate offsets.
  • Replace use of the full DLineEditEx rect for placeholder elidedText width and drawText target with a calculated textRect derived from the embedded QLineEdit
  • Use QLineEdit::textMargins to compute the actual usable text area, subtracting icon padding from the placeholder rendering region
  • Map the embedded QLineEdit’s origin into the DLineEditEx coordinate system via mapTo(this, QPoint(0, 0)) to build an accurate lineEditRect
  • Update elidedText width parameter to textRect.width() and draw the centered single-line placeholder within textRect while leaving tooltip logic unchanged
src/widgets/dlineeditex.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

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.

2 participants