Skip to content

Commit 9686398

Browse files
Kakueeendeepin-bot[bot]
authored andcommitted
fix: adjust list item height calculation for dynamic rows
Previously the list item height was fixed to 36px, redefined as the macro `ListItemHeight`. This change removes the fixed height and calculates the row height dynamically based on font metrics, allowing the list to properly display items with multi-line content. Additionally, the drawing rectangle for the item name now uses `nameTextMaxWidth` instead of the actual text width, ensuring consistent alignment. The web static text ellipsis handling is also fixed to correctly subtract the marker width. Log: Adjusted list item height for dynamic rows in grand search results Influence: 1. Test single-line and multi-line item display in grand search results list 2. Verify that row height adapts correctly for items with and without second line 3. Check alignment of item name text when ellipsis is applied 4. Confirm web static text items show correct marker and ellipsis behavior 5. Test under different font sizes and DPI settings fix: 调整列表项行高为动态计算 之前列表项高度固定为 36px,定义为宏 `ListItemHeight`。此更改移除了固定高 度,基于字体度量动态计算行高,使列表能够正常显示多行内容。同时修改了名称 绘制矩形区域,使用 `nameTextMaxWidth` 确保对齐一致。修复了 web 静态文本 省略号处理中标记宽度的减法逻辑。 Log: 调整全局搜索结果列表行高为动态高度 Influence: 1. 测试全局搜索结果列表中单行和多行项目的显示效果 2. 验证有/无第二行时行高是否正确自适应 3. 检查名称文本省略时的对齐情况 4. 确认 web 静态文本项目标记和省略行为正确 5. 在不同字体大小和 DPI 设置下测试
1 parent fa2bdb8 commit 9686398

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/grand-search/gui/exhibition/matchresult/listview/grandsearchlistdelegate.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <QApplication>
2121
#include <QToolTip>
2222

23-
#define ListItemHeight 36 // 列表行高(单行)
2423
#define ListIconSize 24 // 列表图标大小
2524
#define ListRowWidth 740 // 列表行宽
2625
#define ItemDataSpacing 10 // 信息显示间隔
@@ -101,13 +100,13 @@ QSize GrandSearchListDelegate::sizeHint(const QStyleOptionViewItem &option, cons
101100
}
102101
}
103102

104-
if (!hasSecondLine)
105-
return QSize(ListRowWidth, ListItemHeight);
106-
107103
QFontMetrics nameFm(DFontSizeManager::instance()->get(DFontSizeManager::T6));
108-
QFontMetrics contextFm(DFontSizeManager::instance()->get(DFontSizeManager::T8));
109-
int totalHeight = ListLineMargin + nameFm.height() + ContextLineSpacing + contextFm.height() + ListLineMargin;
110-
totalHeight = qMax(totalHeight, ListItemHeight);
104+
int totalHeight = ListLineMargin * 2 + nameFm.height();
105+
106+
if (hasSecondLine) {
107+
QFontMetrics contextFm(DFontSizeManager::instance()->get(DFontSizeManager::T8));
108+
totalHeight += ContextLineSpacing + contextFm.height();
109+
}
111110

112111
return QSize(ListRowWidth, totalHeight);
113112
}
@@ -309,7 +308,8 @@ void GrandSearchListDelegate::drawItemName(QPainter *painter, const QModelIndex
309308
if (elidedName != name && GRANDSEARCH_CLASS_WEB_STATICTEXT == searcher) {
310309
static const QString markStr = name.right(1);
311310
static const int markWidth = fontMetrics.size(Qt::TextSingleLine, markStr).width();
312-
elidedName = fontMetrics.elidedText(name.left(name.size() - 1), Qt::ElideRight, nameTextMaxWidth - markWidth);
311+
nameTextMaxWidth -= markWidth;
312+
elidedName = fontMetrics.elidedText(name.left(name.size() - 1), Qt::ElideRight, nameTextMaxWidth);
313313
elidedName.append(markStr);
314314
}
315315

@@ -346,8 +346,7 @@ void GrandSearchListDelegate::drawItemName(QPainter *painter, const QModelIndex
346346
nameCursor.endEditBlock();
347347

348348
QAbstractTextDocumentLayout::PaintContext paintContext;
349-
int actualNameWidth = fontMetrics.size(Qt::TextSingleLine, elidedName).width();
350-
QRect drawRect(textStartX, startY, actualNameWidth, fontMetrics.height());
349+
QRect drawRect(textStartX, startY, nameTextMaxWidth, fontMetrics.height());
351350

352351
// 文件名被省略时,记录 tooltip 区域
353352
if (elidedName != name) {

0 commit comments

Comments
 (0)