Skip to content

fix: The "Add Group" button cannot be focused using the Tab key.#522

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
JWWTSL:master
Apr 21, 2026
Merged

fix: The "Add Group" button cannot be focused using the Tab key.#522
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL
Copy link
Copy Markdown
Contributor

@JWWTSL JWWTSL commented Apr 20, 2026

log: Explicitly specified the tab order using setTabOrder(m_pushButton, m_addGroupButton) and set the focus policy of both buttons to Qt::TabFocus.

pms: bug-337813

log: Explicitly specified the tab order using setTabOrder(m_pushButton, m_addGroupButton) and set the focus policy of both buttons to Qt::TabFocus.

pms: bug-337813
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的修改主要是为了改进用户界面的键盘导航体验,特别是 Tab 键的焦点顺序控制。以下是对这段 diff 的详细审查和改进建议:

1. 代码逻辑与语法审查

现状:
代码逻辑是正确的,语法符合 Qt/C++ 规范。使用了 Qt::TabFocussetTabOrder 来显式控制焦点行为。

潜在问题:

  • 焦点策略的一致性:代码中只显式设置了 m_addGroupButtonm_pushButton 的焦点策略为 Qt::TabFocus。如果 m_searchEditm_listWidget 的默认焦点策略不是 TabFocus(例如 StrongFocusClickFocus),那么 setTabOrder 调用可能无法达到预期效果,因为 setTabOrder 只能对那些可以接受 Tab 键焦点的控件起作用。

2. 代码质量改进建议

建议:
为了确保代码的健壮性和一致性,建议显式设置所有参与 Tab 导航的控件的焦点策略。

修改后的代码示例:

void RemoteManagementPanel::initUI()
{
    // ... 初始化代码 ...

    // 显式设置所有相关控件的焦点策略,确保 Tab 导航的一致性
    m_searchEdit->setFocusPolicy(Qt::TabFocus);
    m_listWidget->setFocusPolicy(Qt::TabFocus);
    m_addGroupButton->setFocusPolicy(Qt::TabFocus);
    m_pushButton->setFocusPolicy(Qt::TabFocus);

    // ... 其他代码 ...

    // 显式设置 Tab 焦点顺序,匹配视觉布局
    setTabOrder(m_searchEdit->lineEdit(), m_listWidget);
    setTabOrder(m_listWidget, m_pushButton);
    setTabOrder(m_pushButton, m_addGroupButton);
}

3. 代码性能审查

影响:

  • 这些修改对性能的影响微乎其微。setFocusPolicysetTabOrder 都是在 UI 初始化阶段调用的轻量级操作,不会影响运行时性能。

4. 代码安全审查

安全性:

  • 此处没有直接的安全隐患。不过,良好的焦点管理可以防止用户在快速操作时误触其他控件,从而间接提升操作安全性。

5. 其他建议

  1. 注释完整性:建议在 setTabOrder 调用处添加更详细的注释,说明视觉布局的顺序,以便后续维护者理解。

    // 显式设置 Tab 焦点顺序,匹配视觉布局:
    // 搜索框 -> 列表 -> 添加按钮 -> 添加分组按钮
    setTabOrder(m_searchEdit->lineEdit(), m_listWidget);
    setTabOrder(m_listWidget, m_pushButton);
    setTabOrder(m_pushButton, m_addGroupButton);
  2. 控件依赖检查:确保 m_searchEdit->lineEdit() 在调用时不会返回 nullptr。如果 m_searchEditDLineEdit 或类似控件,通常 lineEdit() 是安全的,但为了防御性编程,可以添加检查:

    if (auto lineEdit = m_searchEdit->lineEdit()) {
        setTabOrder(lineEdit, m_listWidget);
    }
  3. 自动化测试:建议添加 UI 自动化测试,验证 Tab 键导航顺序是否符合预期,特别是在 UI 布局发生变化时。

总结

这段代码的修改方向是正确的,主要改进了键盘导航体验。为了进一步提升代码质量,建议:

  • 显式设置所有相关控件的焦点策略。
  • 添加更详细的注释。
  • 考虑对 lineEdit() 的返回值进行防御性检查。
  • 添加 UI 自动化测试以验证焦点顺序。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL, lzwind

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

@JWWTSL
Copy link
Copy Markdown
Contributor Author

JWWTSL commented Apr 21, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Apr 21, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 25bda81 into linuxdeepin:master Apr 21, 2026
15 checks passed
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