From b51bcb0b3eb61d0f8dca7a24eabb7444c1035457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Mon, 12 Oct 2026 22:14:01 +0800 Subject: [PATCH] fix: prevent More menu arrow overlapping its label --- .../more-button-acceptance-20261012.md | 25 +++++++++++++++ docs/user/一叶知秋_重构版_更新说明.md | 1 + src/dx_productivity/ui/floating_toolbar.py | 7 ++++ src/dx_productivity/ui/theme.py | 10 ++++++ tests/ui/test_compact_floating_window.py | 7 ++-- tests/ui/test_horizontal_toolbar.py | 32 +++++++++++++++++++ 6 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 docs/testing/more-button-acceptance-20261012.md diff --git a/docs/testing/more-button-acceptance-20261012.md b/docs/testing/more-button-acceptance-20261012.md new file mode 100644 index 0000000..9bb7b8b --- /dev/null +++ b/docs/testing/more-button-acceptance-20261012.md @@ -0,0 +1,25 @@ +# “更多”按钮重叠修复验收(2026-10-12) + +原按钮继承全局 QToolButton 的 30 像素内容宽度,实际外宽 32 像素;“更多”文字宽 26 像素,菜单指示器还占 12 像素,因此无法并排显示。此前仅修正展开/收起按钮,遗漏了此菜单按钮。 + +修复使用独立样式和 60 逻辑像素按钮,显式下箭头与文字由 Qt 并排布局,隐藏重复的自动菜单指示器。极窄屏进入箭头菜单模式,恢复可用宽度后重新显示“更多”。InstantPopup 及原有菜单动作保持原路由。 + +## 验证 + +- 回归断言在修改前失败:实际 32 像素小于文字、箭头及间距所需的 52 像素。记录:`build/test-evidence/more-button-red.xml`。 +- 修复后工具栏、主窗口、窄屏溢出、位置恢复等 33 项通过。记录:`build/test-evidence/more-button-green.xml`。 +- 明暗主题在 100%/125%/150% Qt 缩放下渲染;图片:`build/test-evidence/more-button/scale-*.png`。 +- 最终便携包 15 项入口/运行库检查通过,另 1 项 ZIP 校验通过。记录:`build/test-evidence/more-button-packaged.xml`、`more-button-manifest.xml`。 +- 最终 EXE 在独立 1GPHY 验收工程中由原生菜单打开,桥接已连接。实际 125% DPI 下“更多”外宽 75 物理像素,真实鼠标打开菜单、设置路由及两次主题切换均通过;PrintWindow 截图确认文字和箭头没有重叠。 +- 收起后工具栏持续运行,未写回器件。原生记录:`%LOCALAPPDATA%/DxProductivity/acceptance/more-button-20261012/more-native.json`;图片:同目录 `toolbar-final.png`、`toolbar-dark.png`、`more-popup.png`。 + +拖动和位置恢复的现有测试原先假设固定的 20 像素横坐标;增加菜单宽度后会触及离屏测试显示器的右边界。断言改为验证边界限制后的坐标和实际保存位置,边界处理逻辑未修改。 + +## 发布包 + +- 目录:`release/一叶知秋_重构版_横向工具栏版`。 +- ZIP:`release/一叶知秋_重构版_横向工具栏版_Win11_x64.zip`。 +- ZIP SHA-256:`a35f46113e6693d9b1129d64fb91955c02cdd853d6c1817d7c979a11e494c90c`。 +- EXE SHA-256:`2ce88c0df54c2d28f8f7990aa7debbe85a4ab44d2c7d2efdf9c91a30b0a97a25`。 + +本记录仅验证菜单按钮修复及相关窗口行为;业务功能的完整实机记录见 `toolbar-acceptance-20261011.md`。PON 全工程快照阻塞和长会话集合内存增长未在本次解决。 diff --git a/docs/user/一叶知秋_重构版_更新说明.md b/docs/user/一叶知秋_重构版_更新说明.md index 6785c53..d033927 100644 --- a/docs/user/一叶知秋_重构版_更新说明.md +++ b/docs/user/一叶知秋_重构版_更新说明.md @@ -5,6 +5,7 @@ - 工具以一排置顶工具栏常驻,提供 Start、位号、属性、显示、检查、网络、BOM 和 PDF;历史、设置、刷新、主题及退出放在“更多”中。 - 点击功能展开对应面板,再点同一功能或“收起面板”收起。面板关闭和最小化也会收起;退出整个工具使用“更多 → 退出工具”。 - 工具栏末尾使用明确的“展开 ▾ / 收起 ▴”按钮;展开内容以无标题栏卡片贴在工具栏下方,不再显示独立应用窗口的标题框。 +- 修复“更多”的文字与菜单箭头重叠;正常宽度下两者并排,极窄屏自动保留箭头菜单入口,屏幕恢复后显示文字。 - 收起后工具栏继续显示选择与任务状态;悬停可查看完整位号、工程、图页和状态信息。拖动左侧手柄移动,位置与各页面大小会保存。 - 页面移除固定左导航、重复标题与说明,操作按钮移到对应页面。低频设置折叠为高级选项,并显示当前有效参数摘要。 - PDF 保留三种范围、输出目录、打开目录和保存后自动导出;配色、文字处理与引擎设置可在高级选项中调整。 diff --git a/src/dx_productivity/ui/floating_toolbar.py b/src/dx_productivity/ui/floating_toolbar.py index 621335c..3b77283 100644 --- a/src/dx_productivity/ui/floating_toolbar.py +++ b/src/dx_productivity/ui/floating_toolbar.py @@ -94,7 +94,10 @@ class FloatingToolbar(QWidget): self.status_label.setAccessibleName('当前桥接、选择与任务状态') layout.addWidget(self.status_label) self.more_button = QToolButton() + self.more_button.setObjectName('toolbarMore') self.more_button.setText('更多') + self.more_button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) + self.more_button.setArrowType(Qt.ArrowType.DownArrow) self.more_button.setAccessibleName('更多') self.more_button.setToolTip('更多功能与应用操作') self.more_button.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) @@ -162,6 +165,8 @@ class FloatingToolbar(QWidget): layout = self.layout() layout.setContentsMargins(5, 4, 5, 4) layout.setSpacing(4) + self.more_button.setText('更多') + self.more_button.setFixedWidth(60) self.drag_handle.show() self.drag_handle.setFixedWidth(20) self.start_button.show() @@ -192,6 +197,8 @@ class FloatingToolbar(QWidget): # in priority order. Start and PDF stay direct until the last stage. layout.setContentsMargins(2, 4, 2, 4) layout.setSpacing(2) + self.more_button.setText('') + self.more_button.setFixedWidth(28) self.drag_handle.setFixedWidth(12) self.start_button.setText('') self.start_button.setFixedWidth(28) diff --git a/src/dx_productivity/ui/theme.py b/src/dx_productivity/ui/theme.py index f39aa40..4af22db 100644 --- a/src/dx_productivity/ui/theme.py +++ b/src/dx_productivity/ui/theme.py @@ -319,6 +319,16 @@ def _stylesheet(tokens: ThemeTokens) -> str: padding: 0 7px; text-align: center; }} + QToolButton#toolbarMore {{ + min-width: 26px; + max-width: 16777000px; + padding: 0; + }} + QToolButton#toolbarMore::menu-indicator {{ + image: none; + width: 0px; + height: 0px; + }} QFrame#statusStrip {{ background: {tokens.surface}; border-top: 1px solid {tokens.border}; diff --git a/tests/ui/test_compact_floating_window.py b/tests/ui/test_compact_floating_window.py index 9e3da26..f7879fc 100644 --- a/tests/ui/test_compact_floating_window.py +++ b/tests/ui/test_compact_floating_window.py @@ -71,7 +71,9 @@ def test_drag_only_handle_moves_toolbar_and_panel_without_switching(qtbot, monke ): event = QMouseEvent(kind, local, global_pos, button, buttons, Qt.KeyboardModifier.NoModifier) QCoreApplication.sendEvent(handle, event) - assert floating.pos() == QPoint(20, 60) + # A wider menu button can reach the edge of the offscreen test monitor. + bounds = floating.screen().availableGeometry() + assert floating.pos() == QPoint(min(20, bounds.right() - floating.width() + 1), 60) assert window.pos().y() == panel_position.y() + 20 assert window.pages.currentIndex() == 0 @@ -112,6 +114,7 @@ def test_page_size_and_toolbar_position_restore_without_overwriting_settings(qtb window.show_panel(0) assert window.size().width() == 750 and window.size().height() == 470 window.toolbar.move_within_screen(QPoint(20, 50)) + saved_position = window.toolbar.pos() path = window.layout_preferences.path window.request_exit() from dx_productivity.ui.main_window import MainWindow @@ -119,7 +122,7 @@ def test_page_size_and_toolbar_position_restore_without_overwriting_settings(qtb qtbot.addWidget(restored) restored.show_panel(7) assert restored.size().width() == 700 and restored.size().height() == 410 - assert restored.toolbar.pos() == QPoint(20, 50) + assert restored.toolbar.pos() == saved_position def test_menu_registration_blocks_exit_but_not_panel_hide(qtbot, monkeypatch, tmp_path): diff --git a/tests/ui/test_horizontal_toolbar.py b/tests/ui/test_horizontal_toolbar.py index 7ec2112..4b5dfdd 100644 --- a/tests/ui/test_horizontal_toolbar.py +++ b/tests/ui/test_horizontal_toolbar.py @@ -75,6 +75,38 @@ def test_expanded_panel_is_a_frameless_tool_card(qtbot): assert window.centralWidget().objectName() == 'appRoot' +def test_more_button_reserves_room_for_text_and_arrow_in_both_themes(qtbot, qapp, tmp_path): + from PySide6.QtWidgets import QStyle + from dx_productivity.ui.app import create_application + from dx_productivity.ui.theme import Theme, apply_theme + + create_application([]) + window = MainWindow(layout_path=tmp_path / 'layout.json') + qtbot.addWidget(window) + window.show_toolbar() + toolbar = window.toolbar + button = toolbar.more_button + for theme in (Theme.LIGHT, Theme.DARK): + apply_theme(qapp, theme) + toolbar.refresh_theme(theme) + toolbar.fit_available_width(1100) + qapp.processEvents() + text_width = button.fontMetrics().horizontalAdvance('更多') + arrow_width = button.style().pixelMetric(QStyle.PixelMetric.PM_MenuButtonIndicator) + assert button.width() >= text_width + arrow_width + 14 + assert button.text() == '更多' + assert toolbar.rect().contains(button.geometry()) + + toolbar.fit_available_width(96) + qapp.processEvents() + assert toolbar.rect().contains(button.geometry()) + assert button.menu() is toolbar.more_menu + toolbar.fit_available_width(1100) + qapp.processEvents() + assert button.text() == '更多' + assert button.width() >= text_width + arrow_width + 14 + + def test_passive_status_keeps_host_focus_and_tracks_background_task(qtbot, qapp, tmp_path, monkeypatch): from types import SimpleNamespace from PySide6.QtWidgets import QWidget