Skip to content

fix: fix AlertToolTip positioning and z-order issues#589

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:master
Mar 19, 2026
Merged

fix: fix AlertToolTip positioning and z-order issues#589
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Mar 19, 2026

  1. Changed AlertToolTip positioning from relative to absolute
    coordinates by calculating global position of target item
  2. Added parent assignment to Overlay.overlay to ensure proper z-
    ordering above other UI elements
  3. Added import for QtQuick.Controls to access Overlay component
  4. Modified x and y calculations to use global coordinates instead of
    local coordinates
  5. Added __itemGlobalPos property to compute cumulative position by
    traversing parent hierarchy

Log: Fixed AlertToolTip display issues where tooltips were hidden behind
other UI elements

Influence:

  1. Test AlertToolTip display with various target elements at different
    hierarchy levels
  2. Verify tooltip appears above all other UI elements including dialogs
    and popups
  3. Test tooltip positioning accuracy when target element is nested in
    multiple containers
  4. Verify smooth animation behavior during tooltip show/hide transitions
  5. Test tooltip display in complex layout scenarios with overlapping
    elements

fix: 修复AlertToolTip定位和层级问题

  1. 将AlertToolTip定位从相对坐标改为绝对坐标,通过计算目标项的全局位置
  2. 添加父级设置为Overlay.overlay以确保正确的z轴排序,显示在其他UI元素
    之上
  3. 添加QtQuick.Controls导入以访问Overlay组件
  4. 修改x和y计算使用全局坐标而非局部坐标
  5. 添加__itemGlobalPos属性通过遍历父级层次结构计算累积位置

Log: 修复AlertToolTip显示问题,解决工具提示被其他UI元素遮挡的情况

Influence:

  1. 测试AlertToolTip在不同层级目标元素上的显示
  2. 验证工具提示是否显示在所有其他UI元素(包括对话框和弹出窗口)之上
  3. 测试当目标元素嵌套在多个容器中时工具提示定位的准确性
  4. 验证工具提示显示/隐藏过渡时的平滑动画行为
  5. 测试在复杂布局场景中工具提示的显示效果

PMS: BUG-352961

Summary by Sourcery

Adjust AlertToolTip to use global positioning and the application overlay for correct display layering.

Bug Fixes:

  • Resolve AlertToolTip being obscured by other UI elements by rendering it in the global overlay layer and removing custom z-ordering.
  • Fix inaccurate AlertToolTip placement for deeply nested target elements by basing coordinates on the target's global position.

Enhancements:

  • Add a reusable helper property to compute a target item's global coordinates for tooltip positioning.

1. Changed AlertToolTip positioning from relative to absolute
coordinates by calculating global position of target item
2. Added parent assignment to Overlay.overlay to ensure proper z-
ordering above other UI elements
3. Added import for QtQuick.Controls to access Overlay component
4. Modified x and y calculations to use global coordinates instead of
local coordinates
5. Added __itemGlobalPos property to compute cumulative position by
traversing parent hierarchy

Log: Fixed AlertToolTip display issues where tooltips were hidden behind
other UI elements

Influence:
1. Test AlertToolTip display with various target elements at different
hierarchy levels
2. Verify tooltip appears above all other UI elements including dialogs
and popups
3. Test tooltip positioning accuracy when target element is nested in
multiple containers
4. Verify smooth animation behavior during tooltip show/hide transitions
5. Test tooltip display in complex layout scenarios with overlapping
elements

fix: 修复AlertToolTip定位和层级问题

1. 将AlertToolTip定位从相对坐标改为绝对坐标,通过计算目标项的全局位置
2. 添加父级设置为Overlay.overlay以确保正确的z轴排序,显示在其他UI元素
之上
3. 添加QtQuick.Controls导入以访问Overlay组件
4. 修改x和y计算使用全局坐标而非局部坐标
5. 添加__itemGlobalPos属性通过遍历父级层次结构计算累积位置

Log: 修复AlertToolTip显示问题,解决工具提示被其他UI元素遮挡的情况

Influence:
1. 测试AlertToolTip在不同层级目标元素上的显示
2. 验证工具提示是否显示在所有其他UI元素(包括对话框和弹出窗口)之上
3. 测试当目标元素嵌套在多个容器中时工具提示定位的准确性
4. 验证工具提示显示/隐藏过渡时的平滑动画行为
5. 测试在复杂布局场景中工具提示的显示效果

PMS: BUG-352961
@18202781743 18202781743 requested review from BLumia and mhduiy March 19, 2026 07:09
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Converts AlertToolTip from local, z-based positioning to an absolute-positioned overlay tooltip using computed global coordinates, ensuring it renders above all UI elements and animates vertically based on the target’s global position.

Updated class diagram for AlertToolTip positioning and parenting

classDiagram
    class AlertToolTip_Before {
        +int x
        +int y
        +int z
        +Item implicitParent
    }

    class AlertToolTip_After {
        +point __itemGlobalPos
        +int x
        +int y
        +Item parent
    }

    AlertToolTip_Before <.. AlertToolTip_After : updated_to
Loading

Flow diagram for computing AlertToolTip global position

flowchart TD
    A["Start: need tooltip global position"] --> B["Set x = 0, y = 0"]
    B --> C["a = target"]
    C --> D{"a and a.parent?"}
    D -->|yes| E["x += a.x; y += a.y"]
    E --> F["a = a.parent"]
    F --> D
    D -->|no| G["Return Qt.point(x, y) as __itemGlobalPos"]
    G --> H["Set Control.x = __itemGlobalPos.x"]
    H --> I["Set Control.y = __itemGlobalPos.y + target.height + spacing"]
    I --> J["Assign parent = Overlay.overlay"]
Loading

File-Level Changes

Change Details Files
Switch tooltip positioning from local coordinates to computed global coordinates.
  • Introduce __itemGlobalPos point property that walks up the target’s parent chain accumulating x and y offsets
  • Use __itemGlobalPos.x as the tooltip’s x coordinate
  • Use __itemGlobalPos.y plus target.height and spacing as the tooltip’s y coordinate instead of local coordinates
qt6/src/qml/AlertToolTip.qml
Move tooltip into the overlay layer instead of relying on z-order.
  • Set parent of the Control to Overlay.overlay so it renders in the overlay layer above other content
  • Remove explicit z: D.DTK.TopOrder since overlay parenting now controls stacking
qt6/src/qml/AlertToolTip.qml
Enable access to the overlay component used for parenting.
  • Add import QtQuick.Controls to access Overlay.overlay
qt6/src/qml/AlertToolTip.qml

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

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.

Hey - I've found 1 issue, and left some high level feedback:

  • Instead of manually accumulating x/y through the parent chain in __itemGlobalPos, consider using target.mapToItem(Overlay.overlay, 0, 0) (or mapToItem(null, 0, 0) if appropriate) to correctly handle transforms, scaling, and other non‑trivial layout cases.
  • parent: Overlay.overlay assumes an Overlay is available; if this component can be used outside an ApplicationWindow/Overlay context, consider a fallback or guard (e.g., using the window’s contentItem or checking for Overlay.overlay) to avoid runtime errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of manually accumulating x/y through the parent chain in `__itemGlobalPos`, consider using `target.mapToItem(Overlay.overlay, 0, 0)` (or `mapToItem(null, 0, 0)` if appropriate) to correctly handle transforms, scaling, and other non‑trivial layout cases.
- `parent: Overlay.overlay` assumes an Overlay is available; if this component can be used outside an `ApplicationWindow`/`Overlay` context, consider a fallback or guard (e.g., using the window’s contentItem or checking for `Overlay.overlay`) to avoid runtime errors.

## Individual Comments

### Comment 1
<location path="qt6/src/qml/AlertToolTip.qml" line_range="18-26" />
<code_context>

-    x: 0
-    y: (target ? target.height : 0) + (_shown ? DS.Style.control.spacing : 0)
+    property point __itemGlobalPos: {
+        let x = 0, y = 0
+        let a = target
+        while (a && a.parent) {
+            x += a.x
+            y += a.y
+            a = a.parent
+        }
+        return Qt.point(x, y)
+    }
+    x: __itemGlobalPos.x
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Use `mapToItem` instead of manually walking the parent chain for global coordinates.

You can replace the manual accumulation with the mapping API, for example:

```qml
property point __itemGlobalPos: target
    ? target.mapToItem(null, 0, 0)
    : Qt.point(0, 0)
```

This correctly accounts for transforms, scaling, and complex parent relationships and reduces the chance of subtle positioning bugs.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

代码审查意见

1. 语法逻辑

  • 位置计算逻辑:新增的 __itemGlobalPos 属性用于计算目标项的全局位置,通过遍历父级链累加 xy 坐标。这个逻辑是正确的,但需要注意以下几点:
    • 如果 targetnull__itemGlobalPos 会返回 Qt.point(0, 0),这与之前的逻辑一致。
    • 如果 target 的父级链中包含 WindowItem 以外的对象(如 Loader),可能会导致位置计算不准确。
  • 父级设置:将 parent 设置为 Overlay.overlay 是合理的,这样可以确保工具提示显示在所有其他内容之上,但需要确保 Overlay 可用(已导入 QtQuick.Controls)。

2. 代码质量

  • 命名规范__itemGlobalPos 使用了双下划线前缀,这通常表示内部私有属性,但 QML 中更推荐使用单下划线(如 _itemGlobalPos)表示私有属性。
  • 可读性:位置计算逻辑可以提取为单独的函数,以提高可读性和复用性:
    function calculateGlobalPos(item) {
        let x = 0, y = 0
        let a = item
        while (a && a.parent) {
            x += a.x
            y += a.y
            a = a.parent
        }
        return Qt.point(x, y)
    }
  • 注释缺失__itemGlobalPos 的计算逻辑较为复杂,建议添加注释说明其作用。

3. 代码性能

  • 位置计算开销__itemGlobalPos 每次访问时都会重新计算全局位置,如果 target 的父级链较长或频繁变化,可能会影响性能。建议缓存计算结果,并在 target 或其父级位置变化时更新。
  • 绑定优化xy 直接绑定到 __itemGlobalPos 的属性,如果 __itemGlobalPos 频繁变化,可能会导致频繁的布局更新。可以考虑使用 BindingConnections 优化绑定逻辑。

4. 代码安全

  • 空值检查target 可能为 null,虽然代码中已有处理(target ? target.height : 0),但建议在 __itemGlobalPos 中也添加显式检查:
    property point __itemGlobalPos: {
        if (!target) return Qt.point(0, 0)
        let x = 0, y = 0
        let a = target
        while (a && a.parent) {
            x += a.x
            y += a.y
            a = a.parent
        }
        return Qt.point(x, y)
    }
  • 循环引用风险:如果 target 的父级链中存在循环引用(虽然不太可能),while 循环会无限迭代。可以添加最大迭代次数限制:
    const MAX_ITERATIONS = 100
    let iterations = 0
    while (a && a.parent && iterations < MAX_ITERATIONS) {
        x += a.x
        y += a.y
        a = a.parent
        iterations++
    }

5. 其他建议

  • 动画优化Behavior on y 的动画持续时间固定为 200ms,如果 target 的位置频繁变化,可能会导致动画卡顿。可以考虑动态调整动画时间或禁用动画。
  • z-order:移除了 z: D.DTK.TopOrder,改为通过 parent: Overlay.overlay 控制层级,这是更现代的做法,但需要确保 Overlay 的行为符合预期。

改进后的代码示例

import QtQuick
import QtQuick.Controls
import org.deepin.dtk 1.0 as D
import org.deepin.dtk.style 1.0 as DS

Control {
    id: control

    property Item target: null
    property bool _expired: false
    readonly property bool _shown: control.visible && !_expired

    function calculateGlobalPos(item) {
        if (!item) return Qt.point(0, 0)
        let x = 0, y = 0
        let a = item
        const MAX_ITERATIONS = 100
        let iterations = 0
        while (a && a.parent && iterations < MAX_ITERATIONS) {
            x += a.x
            y += a.y
            a = a.parent
            iterations++
        }
        return Qt.point(x, y)
    }

    property point _itemGlobalPos: calculateGlobalPos(target)
    x: _itemGlobalPos.x
    y: _itemGlobalPos.y + (target ? target.height : 0) + (_shown ? DS.Style.control.spacing : 0)
    Behavior on y {
        NumberAnimation { duration: 200 }
    }
    parent: Overlay.overlay
    opacity: _shown ? 1 : 0
    enabled: _shown
    topPadding: DS.Style.alertToolTip.verticalPadding
    bottomPadding: DS.Style.alertToolTip.verticalPadding
    leftPadding: DS.Style.alertToolTip.horizontalPadding
    rightPadding: DS.Style.alertToolTip.horizontalPadding
    implicitWidth: target ? Math.min(DS.Style.control.implicitWidth(control), target.width) : DS.Style.control.control.implicitWidth(control)
    implicitHeight: DS.Style.control.implicitHeight(control)

    Timer {
        id: autoHideTimer
        // ...
    }
}

总结

  • 改进后的代码提高了可读性和安全性,同时优化了性能。
  • 建议在实际使用中测试 Overlay 的行为,确保工具提示的显示和隐藏符合预期。

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@18202781743 18202781743 merged commit dc000a4 into linuxdeepin:master Mar 19, 2026
18 of 21 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.

4 participants