fix(ui): fix tab titles shifting left after window restore from maximize#260
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom Apr 20, 2026
Merged
Conversation
Three changes to fix maximize→restore tab offset bug: 1. Disable Qt internal expanding on inner QTabBar to prevent it from overriding manual tab sizes. 2. Fix updateTabWidth formula to use (width-44)/tabCount matching DTK embedStyle layout, move setUsesScrollButtons outside loop. 3. Force inner QTabBar re-layout in resizeEvent to reset stale scrollOffset that DTK's paintEvent never corrects. 修复窗口最大化还原后标签页偏左不显示的问题。DTK的paintEvent 覆盖了Qt原生实现导致scrollOffset无法自动修正。 Log: 修复最大化还原后标签页偏移问题 PMS: BUG-306499 Influence: 修复后窗口最大化还原时标签页标题正常显示,不再偏移。
deepin pr auto review这段代码主要对 1. 语法与逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
综合改进建议
修改后的代码示例建议// 在头文件中添加成员变量
// private:
// QTabBar *m_innerTabBar = nullptr;
// static const int kTabMargin = 44;
// static const int kTabMinWidth = 140;
// static const int kTabHeight = 37;
// 构造函数中
DocTabBar::DocTabBar(QWidget *parent)
: DTabBar(parent)
{
// ... 初始化代码 ...
// 缓存内部 TabBar 指针
m_innerTabBar = findChild<QTabBar *>();
if (m_innerTabBar) {
m_innerTabBar->setExpanding(false);
}
// ...
}
void DocTabBar::updateTabWidth()
{
int tabCount = count();
if (tabCount == 0) return;
int innerWidth = this->width() - kTabMargin;
int tabWidth = innerWidth / tabCount;
// 如果计算宽度小于最小宽度,启用滚动条并固定宽度
bool useScroll = tabWidth < kTabMinWidth;
setUsesScrollButtons(useScroll);
for (int i = 0; i < tabCount; i++) {
// 只有在不滚动时才使用计算出的宽度,否则使用最小宽度
// 这样可以避免强制设置大宽度导致总宽度超出窗口
int w = useScroll ? kTabMinWidth : tabWidth;
setTabMinimumSize(i, QSize(w, kTabHeight));
setTabMaximumSize(i, QSize(w, kTabHeight));
}
}
void DocTabBar::resizeEvent(QResizeEvent *e)
{
// 先更新宽度逻辑
updateTabWidth();
// 调用父类处理
DTabBar::resizeEvent(e);
// Hack: 强制触发内部 TabBar 布局更新以解决渲染故障
if (m_innerTabBar) {
int w = m_innerTabBar->width();
int h = m_innerTabBar->height();
m_innerTabBar->resize(w + 1, h);
m_innerTabBar->resize(w, h);
}
} |
lzwind
approved these changes
Apr 20, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx 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 |
Contributor
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three changes to fix maximize→restore tab offset bug:
修复窗口最大化还原后标签页偏左不显示的问题。DTK的paintEvent
覆盖了Qt原生实现导致scrollOffset无法自动修正。
Log: 修复最大化还原后标签页偏移问题
PMS: BUG-306499
Influence: 修复后窗口最大化还原时标签页标题正常显示,不再偏移。