fix: correct search dropdown position offset - #791
Conversation
1. Root cause: SearchResultDialog (Popup) used searchEdit.x which is a local coordinate relative to titleRowLayout, but Popup renders in Overlay layer with a different coordinate system 2. Fix: set parent to titleBar and use mapToItem() to convert searchEdit coordinates into titleBar coordinate system 3. Impact: only affects search result dropdown position, no change to search logic or event handling Log: fix search result dropdown misalignment with search box Influence: 1. Test searching by album name with songs in library 2. Verify dropdown appears below and centered on search box 3. Resize window and verify dropdown stays aligned fix: 修复搜索关联栏位置错位 1. 根因:SearchResultDialog(Popup)使用 searchEdit.x 定位,但该值 是相对于 titleRowLayout 的局部坐标,而 Popup 显示在 Overlay 层 使用不同坐标系,导致下拉框偏移 2. 方案:将 Popup 的 parent 设为 titleBar,使用 mapToItem() 将 searchEdit 坐标转换到 titleBar 坐标系后定位 3. 影响:仅影响搜索结果下拉框显示位置,不影响搜索逻辑和事件处理 Log: 修复搜索关联栏位置错位 Influence: 1. 测试搜索已导入歌曲的专辑名 2. 验证下拉框出现在搜索框正下方居中对齐 3. 调整窗口大小后验证下拉框保持对齐 PMS: BUG-375805
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes search result dropdown drift by parenting the popup to the title bar and converting the search field coordinates before positioning it, keeping the dropdown aligned across layout and window-size changes. Flow diagram for corrected search dropdown positioningflowchart LR
SearchEdit[SearchEdit in titleRowLayout] -->|"mapToItem(titleBar, 0, 0)"| TitleBarCoords[titleBar coordinates]
SearchEdit -->|"mapToItem(titleBar, 0, searchEdit.height)"| DropdownY[Below search field]
TitleBarCoords --> Position[Calculate Popup x]
DropdownY --> PositionY[Calculate Popup y + 4]
Position --> Popup[SearchResultDialog parented to titleBar]
PositionY --> Popup
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/music-player/mainwindow/WindowTitlebar.qml" line_range="342-344" />
<code_context>
- x: searchEdit.x - (width - searchEdit.width) / 2
- y: 50
+ parent: titleBar
+ x: searchEdit.mapToItem(titleBar, 0, 0).x
+ - (width - searchEdit.width) / 2
+ y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4
visible: false
</code_context>
<issue_to_address>
**issue (bug_risk):** The `x` and `y` bindings call `mapToItem()` without directly depending on `searchEdit.x`, `searchEdit.y`, or the ancestor layout geometry. QML does not receive geometry-change notifications from the internal coordinate calculation, so after the title-bar layout moves during a window resize, the Popup retains its previous mapped position and becomes misaligned again.
**Triggers:** When resizing the window or otherwise moving `searchEdit` without changing its explicitly referenced `width` or `height`.
**Suggested fix:** Update the Popup position from `searchEdit` geometry change handlers or bind through explicit geometry properties that trigger reevaluation, then perform the coordinate conversion.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| x: searchEdit.mapToItem(titleBar, 0, 0).x | ||
| - (width - searchEdit.width) / 2 | ||
| y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4 |
There was a problem hiding this comment.
issue (bug_risk): The x and y bindings call mapToItem() without directly depending on searchEdit.x, searchEdit.y, or the ancestor layout geometry. QML does not receive geometry-change notifications from the internal coordinate calculation, so after the title-bar layout moves during a window resize, the Popup retains its previous mapped position and becomes misaligned again.
Triggers: When resizing the window or otherwise moving searchEdit without changing its explicitly referenced width or height.
Suggested fix: Update the Popup position from searchEdit geometry change handlers or bind through explicit geometry properties that trigger reevaluation, then perform the coordinate conversion.
deepin pr auto reviewAI 代码审查报告项目: linuxdeepin/deepin-music 总体评分:99 分
审查结论: 代码审查通过。代码变更修复了搜索结果下拉框的位置偏移问题,使用 代码变更概述本次 PR 修复了 deepin-music 播放器中搜索结果下拉框( 根因: 修复方案: 将 Popup 的 id: searchResultComponent
SearchResultDialog {
width: 360
- x: searchEdit.x - (width - searchEdit.width) / 2
- y: 50
+ parent: titleBar
+ x: searchEdit.mapToItem(titleBar, 0, 0).x
+ - (width - searchEdit.width) / 2
+ y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4
visible: false四维度详细分析1. 语法逻辑 ✓(25/25)
2. 代码质量 ✓(24/25)
优点:
3. 代码性能 ✓(20/20)
4. 代码安全 ✓(30/30)
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
改进建议// SearchResultDialog 定位:将 searchEdit 坐标映射到 titleBar 坐标系
// 解决 Popup Overlay 层与搜索框坐标系不一致导致的下拉框偏移问题
parent: titleBar
x: searchEdit.mapToItem(titleBar, 0, 0).x
- (width - searchEdit.width) / 2
y: searchEdit.mapToItem(titleBar, 0, searchEdit.height).y + 4审查清单
本报告由 AI 代码审查工具自动生成 | 扫描时间:2026-09-02 10:55:00 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pengfeixx, wyu71 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Root Cause Analysis
The search result dropdown (
SearchResultDialog, a QMLPopup) was misaligned with the search box. The root cause is a coordinate system mismatch:searchEdit.xis a local coordinate relative totitleRowLayout, but thePopupis rendered in the Overlay layer which uses a different coordinate system. UsingsearchEdit.xdirectly for the Popup'sxposition — and a hardcodedy: 50— caused the dropdown to drift from the search box, especially when window width or title bar layout changed.Key evidence:
WindowTitlebar.qml:341—x: searchEdit.x - (width - searchEdit.width) / 2uses local coordinate without conversionWindowTitlebar.qml:342—y: 50hardcoded, doesn't adapt to layout changessearchEditis a child oftitleRowLayout;SearchResultDialogis aPopuprendered in Overlay — different coordinate systemsFix
Set
parent: titleBaron the Popup and usemapToItem(titleBar, ...)to convertsearchEdit's coordinates intotitleBar's coordinate system before positioning:Change Safety Assessment
WindowTitlebar.qml(searchResultComponent)mapToItemis a standard QML coordinate conversion method;parent: titleBaranchors the Popup to the root element with a stable lifecycleBusiness Impact
Affects only the display position of the search result dropdown. Users searching for songs/artists/albums will see the dropdown correctly aligned below the search box regardless of window size.
Verification Suggestion
根因分析
搜索关联栏(
SearchResultDialog,QMLPopup)与搜索框位置错位。根本原因是坐标系不一致:searchEdit.x是相对于titleRowLayout的局部坐标,而Popup显示在 Overlay 层使用不同坐标系。直接使用searchEdit.x定位 + 硬编码y: 50,导致下拉框偏移,窗口宽度变化时更明显。关键证据:
WindowTitlebar.qml:341—x: searchEdit.x - ...直接使用局部坐标,未做转换WindowTitlebar.qml:342—y: 50硬编码,不随布局变化searchEdit是titleRowLayout子项,SearchResultDialog是 Overlay 层 Popup,坐标系不同修复方案
将 Popup 的
parent设为titleBar,用mapToItem(titleBar, ...)将searchEdit坐标转换到titleBar坐标系后定位。改动安全评估
WindowTitlebar.qml中searchResultComponent的 3 行属性mapToItem是 QML 标准坐标转换方法;parent: titleBar锚定到根元素,生命周期稳定业务影响范围
仅影响搜索结果下拉框的显示位置。用户搜索歌曲/歌手/专辑时,下拉框将正确对齐在搜索框下方,不受窗口大小影响。
验证建议
Summary by Sourcery
Bug Fixes: