fix: correct scroll button enabled state after lazy layoutTabs in DTabBar - #769
fix: correct scroll button enabled state after lazy layoutTabs in DTabBar#769Johnson-zs wants to merge 1 commit into
Conversation
…bBar 1. 在 DTabBarPrivate::tabLayoutChange() 中增加 makeVisible(currentIndex()) 调用; 2. 修复惰性 layoutTabs 路径(如 paintEvent 经 tabRect() 触发)下左右滚动按钮 enabled 状态反转的问题; ===================================== 1. added makeVisible(currentIndex()) call in DTabBarPrivate::tabLayoutChange(); 2. fixed scroll button enabled state inversion in lazy layoutTabs path (e.g. triggered via tabRect() in paintEvent); Log: 修复窗口缩至最小、多 tab 溢出时 DTabBar 左右滚动按钮可点击状态反转的问题,确保惰性布局后按钮状态与实际滚动位置一致
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs 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 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures DTabBar scroll button enabled/disabled state is correctly recalculated after every tab layout, including lazy layoutTabs paths triggered via paintEvent/tabRect, by invoking makeVisible(currentIndex()) in DTabBarPrivate::tabLayoutChange(). Sequence diagram for corrected scroll button state after lazy layoutTabssequenceDiagram
participant DTabBar as DTabBar
participant QTabBarPrivate as QTabBarPrivate
participant DTabBarPrivate as DTabBarPrivate
DTabBar->>DTabBar: paintEvent
DTabBar->>DTabBar: tabRect
DTabBar->>QTabBarPrivate: layoutTabs
QTabBarPrivate-->>DTabBarPrivate: tabLayoutChange
DTabBarPrivate->>DTabBar: tabLayoutChange
DTabBarPrivate->>DTabBarPrivate: updateCloseButtonVisible
DTabBarPrivate->>DTabBarPrivate: makeVisible(currentIndex)
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 left some high level feedback:
- Calling
makeVisible(currentIndex())on everytabLayoutChangemay unintentionally re-center the scroll position around the current tab after any layout, so it’s worth double-checking whether there are scenarios where the user has intentionally scrolled away from the current tab and this call would now override that behavior; if so, consider a condition to limit whenmakeVisibleis invoked.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Calling `makeVisible(currentIndex())` on every `tabLayoutChange` may unintentionally re-center the scroll position around the current tab after any layout, so it’s worth double-checking whether there are scenarios where the user has intentionally scrolled away from the current tab and this call would now override that behavior; if so, consider a condition to limit when `makeVisible` is invoked.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/src/widgets/dtabbar.cpp b/src/widgets/dtabbar.cpp
index 7584a4867..b2ad850e5 100644
--- a/src/widgets/dtabbar.cpp
+++ b/src/widgets/dtabbar.cpp
@@ -1589,6 +1589,10 @@ void DTabBarPrivate::tabLayoutChange()
q->tabLayoutChange();
// 更新关闭按钮的显示
updateCloseButtonVisible();
+ // 修正滚动按钮的启用状态:layoutTabs() 会将 leftB 重置为 disabled,
+ // 需根据实际 scrollOffset 重新计算,修复惰性布局路径(如 paintEvent
+ // 中经 tabRect() 触发的 layoutTabs)下左右滚动按钮 enabled 状态反转的问题。
+ makeVisible(currentIndex());
}
void DTabBarPrivate::initStyleOption(QStyleOptionTab *option, int tabIndex) const |
根因分析
窗口缩至最小、多 tab 溢出时,DTabBar 左右滚动按钮可点击状态反转:左侧 disabled(实际最左 tab 已隐藏,应可点),右侧 enabled(最右 tab 已可见,应不可点)。
根因:Qt
QTabBarPrivate::layoutTabs()硬编码leftB->setEnabled(false),makeVisible()才根据实际scrollOffset修正为正确状态。layoutTabs()存在惰性调用路径(经tabRect()在paintEvent中触发),该路径不调用makeVisible()。DTK 的DTabBar::resizeEvent不触发 QTabBar 子部件的makeVisible,而文管TabBar::resizeEvent的setIconSize(iconSize())临时方案会设置layoutDirty=true触发惰性layoutTabs,导致按钮状态被重置为默认值且无人修正。修复方案
在
DTabBarPrivate::tabLayoutChange()(layoutTabs()末尾调用的虚函数)中增加makeVisible(currentIndex())调用,确保每次layoutTabs()完成后(包括惰性路径)滚动按钮的 enabled 状态根据实际scrollOffset修正。改动安全评估
低风险:不修改函数签名,不删除公开函数,仅增加一行对已有方法
makeVisible的调用(该方法已在startMove、startTabFlash等处使用)。makeVisible内部有validIndex守卫,无递归风险。Summary by Sourcery
Bug Fixes: