Skip to content

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Feb 1, 2026

Added MouseArea with explicit cursorShape to provide default cursor for all areas.

Log: Fix cursor style not updating after theme switch.
pms: BUG-325241

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.

Sorry @re2zero, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@re2zero re2zero force-pushed the bugfix branch 2 times, most recently from 9f46a5c to 99c6954 Compare February 2, 2026 03:01
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, 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

Added MouseArea with explicit cursorShape to provide default cursor for all areas.

Log: Fix cursor style not updating after theme switch.
pms: BUG-325241
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码在 DccWindow.qml 中添加了一个 MouseArea,旨在处理窗口的光标样式。以下是对这段代码的详细审查和改进意见:

1. 语法逻辑审查

  • 语法正确性:代码符合 QML 语法规范,没有语法错误。
  • 逻辑问题
    • MouseAreaanchors.fill: parent 覆盖了整个窗口。
    • enabled: false 表示该 MouseArea 不会接收鼠标事件(点击、悬停等),也不会将事件传递给下层的子项(因为它是直接子项且位于顶层)。这意味着它实际上是一个“透明”的层,除了设置光标外,不参与交互。
    • 潜在冲突:如果 DccWindow 内部有其他需要处理鼠标事件的子控件(如按钮、列表等),虽然 enabled: false 允许事件穿透(即事件会被传递给 MouseArea 下方的兄弟控件或父控件),但在某些复杂的布局或特定的 Qt 版本中,这种“顶层禁用层”可能会导致事件处理的不可预测性,或者干扰底层控件的悬停状态判断。

2. 代码质量审查

  • 可读性:代码结构简单,但缺少注释说明为什么需要这个 MouseArea。建议添加注释解释其作用(例如:强制保持鼠标为箭头样式)。
  • 维护性:如果后续需要修改光标行为,这个硬编码的 Qt.ArrowCursor 可能不够灵活。

3. 代码性能审查

  • 渲染开销:添加一个覆盖全屏的 MouseArea 会增加一个渲染节点。虽然 MouseArea 本身开销不大,但在高性能要求场景下,应尽量避免不必要的层级叠加。
  • 事件处理:即使 enabled: false,鼠标移动事件仍会被系统捕获并传递给这个 MouseArea(尽管它不处理),这会带来轻微的事件处理开销。

4. 代码安全审查

  • 安全性:此更改不涉及安全问题。

5. 改进建议

方案一:优化当前实现(推荐)

如果目的是强制窗口内的鼠标样式始终为箭头,建议将 MouseArea 的作用范围限制在必要区域,或者添加注释说明。同时,考虑使用 cursorShape 属性直接在父窗口上设置(如果框架支持)。

D.ApplicationWindow {
    // ... 其他属性 ...
    
    // 强制窗口内鼠标样式为箭头,防止底层控件改变光标
    MouseArea {
        anchors.fill: parent
        enabled: false  // 允许事件穿透,但不处理任何事件
        cursorShape: Qt.ArrowCursor
    }
    
    // ... 其他子项 ...
}

方案二:使用 hoverEnabled 替代 enabled: false

如果希望鼠标事件穿透但不干扰底层控件的悬停状态,可以尝试以下方式(但需测试是否满足需求):

MouseArea {
    anchors.fill: parent
    hoverEnabled: true  // 启用悬停事件
    propagateComposedEvents: true  // 允许事件传播
    onPositionChanged: {
        mouse.accepted = false  // 拒绝处理事件,允许穿透
    }
    cursorShape: Qt.ArrowCursor
}

方案三:检查是否真的需要 MouseArea

如果 D.ApplicationWindowD.DWindow 支持直接设置 cursorShape,优先使用原生属性:

D.ApplicationWindow {
    cursorShape: Qt.ArrowCursor  // 直接在窗口上设置
    // ...
}

6. 总结

当前代码的功能是强制窗口内的鼠标样式为箭头,但通过全屏 MouseArea 实现可能不是最优解。建议:

  1. 添加注释说明其作用。
  2. 检查是否可以通过窗口原生属性实现。
  3. 如果必须使用 MouseArea,确保它不会干扰底层控件的事件处理。

最终改进后的代码示例(添加注释):

D.ApplicationWindow {
    // ... 其他属性 ...
    
    // 强制窗口内鼠标样式为箭头,防止底层控件改变光标
    MouseArea {
        anchors.fill: parent
        enabled: false  // 允许事件穿透
        cursorShape: Qt.ArrowCursor
    }
    
    // ... 其他子项 ...
}

@re2zero
Copy link
Contributor Author

re2zero commented Feb 2, 2026

/merge

@deepin-bot deepin-bot bot merged commit 1b02d03 into linuxdeepin:master Feb 2, 2026
18 checks passed
@re2zero re2zero deleted the bugfix branch February 2, 2026 05:07
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