Skip to content

fix(Menu): restore spacing between header and list when arrows are hidden - #732

Merged
18202781743 merged 1 commit into
linuxdeepin:v25-flowstylefrom
zqq-dora:fix-menu-header-list-spacing
Oct 21, 2026
Merged

18202781743 merged 1 commit into
linuxdeepin:v25-flowstylefrom
zqq-dora:fix-menu-header-list-spacing

Conversation

@zqq-dora

@zqq-dora zqq-dora commented Oct 21, 2026 •

Copy link
Copy Markdown

Background

PR #728 made ArrowListView's anchors.topMargin conditional on itemsView.interactive so that no extra space is reserved when arrows are absent. However, that topMargin was also the only spacing between a search-box header and the menu items.

When a menu has a header (e.g. a SearchEdit) but no arrows (item count <= maxVisibleItems), the header and the first menu item are flush together with zero gap. Conversely, viewLayout.spacing: 0 in Menu.qml means menus without a header/footer get no extra top/bottom padding, which is correct.

Changes

Menu.qml

  • Add id: headerLoader and id: footerLoader to the header and footer Loaders so their loaded state can be checked.
  • Add Layout.topMargin: headerLoader.item ? 6 : 0 and Layout.bottomMargin: footerLoader.item ? 6 : 0 on ArrowListView, so the 6px gap only appears when a header or footer is actually present, and never when absent.
  • Keep viewLayout.spacing: 0 so menus without header/footer get no extra top/bottom padding.

ArrowListView.qml

  • Set anchors.topMargin to 0 unconditionally; the header/list gap is now handled by Menu.qml's Layout.topMargin so the two do not stack.
  • Split topMargin out of the arrowStrips term in sizedHeight so it is always counted independently.

Effect

  • Menu without header/footer (e.g. right-click menu): no extra spacing, same as before.
  • Menu with header but no arrows (e.g. font menu with search box, 8 items): 6px gap between search box and first item, matching the spacing when arrows are present.
  • Menu with header and arrows (e.g. language menu, >16 items): 6px gap between header and up arrow, consistent layout.

Only the Qt6 (qt6/src/qml/) implementation is changed; Qt5 is left unchanged as v25 ships Qt6 only.


背景

PR #728 将 ArrowListView 的 anchors.topMargin 改为按 itemsView.interactive 条件绑定,无箭头时归零。但该 topMargin 同时也是搜索框 header 与菜单项之间唯一的间距来源。

当菜单有 header(如 SearchEdit 搜索框)但无箭头(项数 <= maxVisibleItems)时,搜索框与第一条菜单项贴在一起,间距为零。而 Menu.qml 中 viewLayout.spacing: 0 使得没有 header/footer 的菜单不会多出上下间距,这是正确的。

改动

Menu.qml

  • 为 header 和 footer Loader 添加 id,以便检测是否加载了内容。
  • 在 ArrowListView 上添加 Layout.topMargin/Layout.bottomMargin,绑定到 header/footer Loader 是否有 item,使 6px 间距仅在 header/footer 存在时出现。
  • viewLayout.spacing 保持 0,无 header/footer 的菜单上下不会多出间距。

ArrowListView.qml

  • anchors.topMargin 无条件设为 0,header 与列表的间距改由 Menu.qml 的 Layout.topMargin 统一控制,避免两者叠加。
  • sizedHeight 中将 topMargin 从 arrowStrips 项中拆出单独计入。

效果

  • 无 header/footer 的菜单(如右键菜单):无多余间距,与之前一致。
  • 有 header 但无箭头的菜单(如字体菜单,8 项):搜索框与第一条菜单项之间 6px 间距,与有箭头时一致。
  • 有 header 且有箭头的菜单(如语言菜单,>16 项):搜索框与上箭头之间 6px 间距,布局一致。

仅修改 Qt6(qt6/src/qml/)实现,Qt5 保持不变,v25 仅使用 Qt6。

Summary by Sourcery

Restore conditional spacing around menu content so header and footer layouts remain consistent without adding padding to menus that lack them.

Bug Fixes:

  • Restore consistent 6px spacing between menu headers or footers and the item list when arrows are hidden, while preserving zero padding for menus without headers or footers.

Enhancements:

  • Unify menu spacing responsibilities between Menu and ArrowListView and keep height calculations accurate across arrow and non-arrow layouts.

…dden

PR linuxdeepin#728 made ArrowListView's topMargin conditional on itemsView.interactive
to avoid extra space when arrows are absent. However, that topMargin was
also the only spacing between a search-box header and the menu items. When
a menu had a header but no arrows (item count <= maxVisibleItems), the
header and the first item were flush together with zero gap.

Menu.qml
- Add ids to the header and footer Loaders so their loaded state can be
  checked.
- Add Layout.topMargin/bottomMargin on ArrowListView bound to whether the
  header/footer Loader actually has an item, so the 6px gap only appears
  when a header or footer is present, and never when absent.
- Keep viewLayout spacing at 0 so menus without header/footer get no extra
  top/bottom padding.

ArrowListView.qml
- Set anchors.topMargin to 0 unconditionally; the header/list gap is now
  handled by Menu.qml's Layout.topMargin so the two do not stack.
- Split topMargin out of the arrowStrips term in sizedHeight so it is
  always counted (it is now always 0 here, but kept for clarity).

Only the Qt6 (qt6/src/qml/) implementation is changed; Qt5 is left
unchanged as v25 ships Qt6 only.

修复带搜索框菜单在无箭头时搜索框与列表项之间缺少间距

PR linuxdeepin#728 将 ArrowListView 的 topMargin 改为按 itemsView.interactive 条件
绑定,无箭头时归零。但该 topMargin 同时也是搜索框 header 与菜单项之间
唯一的间距来源,导致有 header 但无箭头(项数 <= maxVisibleItems)时,
搜索框与第一条菜单项贴在一起。

Menu.qml
- 为 header 和 footer Loader 添加 id,以便检测其是否加载了内容。
- 在 ArrowListView 上添加 Layout.topMargin/bottomMargin,绑定到
  header/footer Loader 是否有 item,使 6px 间距仅在 header/footer
  存在时出现,不存在时不产生多余间距。
- viewLayout spacing 保持 0,无 header/footer 的菜单上下不会多出间距。

ArrowListView.qml
- anchors.topMargin 无条件设为 0,header 与列表的间距改由 Menu.qml 的
  Layout.topMargin 统一控制,避免两者叠加。
- sizedHeight 中将 topMargin 从 arrowStrips 项中拆出单独计入。

仅修改 Qt6(qt6/src/qml/)实现,Qt5 保持不变,v25 仅使用 Qt6。
@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

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

Reviewer's Guide

Restores a 6px gap between loaded menu headers/footers and the item list without adding padding to menus that lack them. Menu.qml now conditionally owns the spacing, while ArrowListView avoids duplicate margins and keeps its implicit-height calculation accurate; only the Qt6 implementation changes.

File-Level Changes

Change Details Files
Move header/footer spacing responsibility into Menu.qml so spacing is present only when those elements are loaded.
  • Added loader IDs to detect loaded header and footer content.
  • Applied conditional 6px top and bottom margins to the list view while retaining zero layout spacing otherwise.
qt6/src/qml/Menu.qml
Make ArrowListView height calculations include list top margin independently from arrow controls.
  • Removed the interactive-dependent top anchor margin and set it to zero.
  • Separated top-margin height from arrow-strip height while preserving arrow spacing calculations.
qt6/src/qml/ArrowListView.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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Hi @zqq-dora. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="qt6/src/qml/ArrowListView.qml" line_range="37" />
<code_context>
         id: contentLayout
         anchors.fill: parent
-        anchors.topMargin: itemsView.interactive ? 6 : 0
+        anchors.topMargin: 0
         spacing: itemsView.interactive ? 6 : 0
         P.ArrowListViewButton {
</code_context>
<issue_to_address>
**ComboBox popups lose top spacing**

When a ComboBox has more items than its `maxVisibleItems` limit, `ArrowListView` sets `anchors.topMargin` to 0, and `ComboBox` provides no replacement margin. Its `sizedHeight` omits the former 6px gap, leaving the popup 6px shorter and the up arrow flush with the popup edge.

Preserve the 6px top gap for ComboBox’s interactive list, either in `ArrowListView` or with an equivalent margin at the ComboBox call site.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

id: contentLayout
anchors.fill: parent
anchors.topMargin: itemsView.interactive ? 6 : 0
anchors.topMargin: 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · ComboBox popups lose top spacing

When a ComboBox has more items than its maxVisibleItems limit, ArrowListView sets anchors.topMargin to 0, and ComboBox provides no replacement margin. Its sizedHeight omits the former 6px gap, leaving the popup 6px shorter and the up arrow flush with the popup edge.

Preserve the 6px top gap for ComboBox’s interactive list, either in ArrowListView or with an equivalent margin at the ComboBox call site.

Prompt for AI agents
In `qt6/src/qml/ArrowListView.qml` at line 37:

**ComboBox popups lose top spacing**

When a ComboBox has more items than its `maxVisibleItems` limit, `ArrowListView` sets `anchors.topMargin` to 0, and `ComboBox` provides no replacement margin. Its `sizedHeight` omits the former 6px gap, leaving the popup 6px shorter and the up arrow flush with the popup edge.

Preserve the 6px top gap for ComboBox’s interactive list, either in `ArrowListView` or with an equivalent margin at the ComboBox call site.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, zqq-dora

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 66f9d42 into linuxdeepin:v25-flowstyle Oct 21, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants