Skip to content

fix(ArrowListView): hide arrows when item count is below maxVisibleItems - #728

Merged
18202781743 merged 1 commit into
linuxdeepin:v25-flowstylefrom
zqq-dora:fix-menu-arrow-always-visible
Oct 21, 2026
Merged

18202781743 merged 1 commit into
linuxdeepin:v25-flowstylefrom
zqq-dora:fix-menu-arrow-always-visible

Conversation

@zqq-dora

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

Copy link
Copy Markdown

Background

PR #726 made both navigation arrows in ArrowListView always instantiated and always visible, regardless of the number of items. While this fixes the issue of arrows flickering or missing on first open, it also means that short menus (e.g. 3 items) now show up/down arrows that serve no purpose, since there is nothing to scroll.

The developer pointed out that master already has a maxVisibleItems mechanism (default 16) on ArrowListView.qml line 14:

property int maxVisibleItems : DS.Style.arrowListView.maxVisibleItems

Combined with itemsView.interactive: itemsView.count > maxVisibleItems and visible: itemsView.interactive on the arrow buttons, this mechanism hides the arrows entirely when the item count does not exceed maxVisibleItems. PR #726 removed visible: itemsView.interactive, which broke this mechanism.

Changes

This PR restores the maxVisibleItems-based arrow visibility mechanism while keeping PR #726s scroll-position-based grey-out behavior for when arrows are visible:

  • ArrowListViewButton.qml: restore active: view.interactive on the Loader. When the list is not scrollable (count ≤ maxVisibleItems), the Loader is inactive — no arrow is instantiated and no layout space is reserved. When scrollable, the arrow is instantiated and its enabled binding greys it out at the top/bottom of the list.

  • ArrowListView.qml: make spacing and topMargin conditional (itemsView.interactive ? 6 : 0) so no extra spacing is added when arrows are absent. The arrow buttons use stepButtonSize.height (16px) for both preferredHeight and minimumHeight so they keep stable dimensions when visible.

  • ArrowListView.qml sizedHeight: re-add the itemsView.count > maxVisibleItems conditional branch. When arrows are not shown, the formula does not include the arrow strip height or top margin, preventing the popup from being sized larger than necessary. When arrows are shown, the formula accounts for 2 * (stepButtonSize.height + spacing) + topMargin to match the actual layout.

Effect

  • Item count ≤ maxVisibleItems (default 16): arrows are hidden, no layout space is reserved, the menu is compact — same as the original master behavior.
  • Item count > maxVisibleItems: arrows are always instantiated and visible (no flicker on first open), and grey out based on scroll position — preserving PR #726s core fix.

PR #726 让箭头无条件常驻,但项数很少时也显示箭头不合理。研发指出 master 原本有 maxVisibleItems(默认 16)机制控制箭头显隐。

本次修复恢复该机制:

  • 恢复 ArrowListViewButton 的 active: view.interactive,Loader 只在可滚动时实例化,不可滚动时不占位
  • spacing 和 topMargin 改为条件绑定(itemsView.interactive ? 6 : 0),无箭头时无多余间距
  • sizedHeight 公式加回条件分支,无箭头时不算箭头区高度,避免 popup 尺寸偏大

效果:项数 ≤ maxVisibleItems 时不显示箭头、不占空间;超过时箭头常驻并按滚动位置变灰。

Summary by Sourcery

Restore conditional ArrowListView arrow visibility based on whether the list exceeds its maximum visible item count.

Bug Fixes:

  • Hide ArrowListView navigation arrows and remove their layout space when the item count does not exceed maxVisibleItems, while retaining scroll-position disabled states for scrollable lists.

Enhancements:

  • Keep popup sizing and layout spacing compact for non-scrollable lists and correctly account for arrow controls when scrolling is required.

@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026

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

Reviewer's Guide

Restores maxVisibleItems-based behavior in ArrowListView: lists at or below the limit hide arrows without occupying space, while longer lists retain arrows with position-aware interaction and correct popup sizing.

Flow diagram for ArrowListView arrow visibility and sizing

flowchart TD
    A[ArrowListView receives item count] --> B{count > maxVisibleItems}
    B -->|No| C[interactive is false]
    C --> D[Hide arrows and remove spacing]
    D --> E[Exclude arrow area from popup height]
    B -->|Yes| F[interactive is true]
    F --> G[Show arrows with position-aware state]
    G --> H[Include arrow area in popup height]
Loading

File-Level Changes

Change Details Files
Restore conditional arrow visibility and sizing based on whether the list exceeds maxVisibleItems.
  • Make arrow buttons active only for scrollable lists and avoid reserving arrow space when inactive.
  • Conditionally apply layout spacing and top margin so hidden arrows do not leave extra gaps.
  • Update popup height calculations to include the arrow area only when arrows are shown.
  • Use the step button dimensions consistently and enforce their minimum height.
  • Extend the copyright year range.
qt6/src/qml/ArrowListView.qml
qt6/src/qml/private/ArrowListViewButton.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

@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 reviewed your changes and they look great!


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

@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.

@zqq-dora
zqq-dora force-pushed the fix-menu-arrow-always-visible branch from 62439b9 to f9f38c0 Compare October 21, 2026 01:40
Arrows should only appear when the list is scrollable (count > maxVisibleItems).
Restore active: view.interactive on the Loader so arrows are not instantiated
when the list doesn't scroll, and make spacing/topMargin conditional so no
extra space is reserved when arrows are absent.
@zqq-dora
zqq-dora force-pushed the fix-menu-arrow-always-visible branch from f9f38c0 to 7187bcf Compare October 21, 2026 02:55
@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 c4aba19 into linuxdeepin:v25-flowstyle Oct 21, 2026
18 of 19 checks passed
zqq-dora added a commit to zqq-dora/dtkdeclarative that referenced this pull request Oct 21, 2026
…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。
18202781743 pushed a commit that referenced this pull request Oct 21, 2026
…dden

PR #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 #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。
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