Skip to content

Commit 0214421

Browse files
18202781743deepin-bot[bot]
authored andcommitted
fix: prevent background type from overriding custom item spacing
1. Changed DStyledItemDelegate to initialize itemSpacing with -1 as default value 2. Added spacing() method to handle negative spacing values 3. Modified setBackgroundType to only set spacing when no custom spacing was set (spacing < 0) 4. Updated all spacing references to use the new spacing() method Log: Fixed issue where setting background type would override custom item spacing values Influence: 1. Test setting custom item spacing values before/after changing background types 2. Verify spacing behavior with different background types (RoundedBackground, ClipCornerBackground) 3. Check layout calculations with custom spacing values 4. Test list view rendering in both LeftToRight and TopToBottom flows fix: 修复设置背景类型会覆盖自定义间距值的问题 1. 修改 DStyledItemDelegate 默认将 itemSpacing 初始化为 -1 2. 新增 spacing() 方法处理负间距值 3. 修改 setBackgroundType 仅在未设置自定义间距时(spacing < 0)才设置 间距 4. 更新所有间距引用使用新的 spacing() 方法 Log: 修复了设置背景类型会覆盖自定义间距值的问题 Influence: 1. 测试在更改背景类型前后设置自定义间距值 2. 验证不同背景类型(RoundedBackground, ClipCornerBackground)下的间距行为 3. 检查使用自定义间距值时的布局计算 4. 测试列表视图在 LeftToRight 和 TopToBottom 两种流式布局下的渲染效果
1 parent bee46d5 commit 0214421

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/widgets/dlistview.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,12 @@ void DListView::setBackgroundType(DStyledItemDelegate::BackgroundType background
777777
if (DStyledItemDelegate *d = qobject_cast<DStyledItemDelegate *>(itemDelegate())) {
778778
d->setBackgroundType(backgroundType);
779779

780-
if (d->backgroundType() == DStyledItemDelegate::RoundedBackground) {
781-
d->setItemSpacing(10);
782-
} else if (d->backgroundType() == DStyledItemDelegate::ClipCornerBackground) {
783-
d->setItemSpacing(1);
784-
} else {
785-
d->setItemSpacing(0);
780+
if (d->spacing() < 0) {
781+
if (d->backgroundType() == DStyledItemDelegate::RoundedBackground) {
782+
d->setItemSpacing(10);
783+
} else if (d->backgroundType() == DStyledItemDelegate::ClipCornerBackground) {
784+
d->setItemSpacing(1);
785+
}
786786
}
787787
}
788788
}

src/widgets/dstyleditemdelegate.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,17 @@ class DStyledItemDelegatePrivate : public DCORE_NAMESPACE::DObjectPrivate
516516
}
517517
}
518518

519+
inline int spacing() const
520+
{
521+
if (itemSpacing < 0)
522+
return 0;
523+
return itemSpacing;
524+
}
525+
519526
DStyledItemDelegate::BackgroundType backgroundType = DStyledItemDelegate::NoBackground;
520527
QMargins margins;
521528
QSize itemSize;
522-
int itemSpacing = 0;
529+
int itemSpacing = -1;
523530
QMap<QModelIndex, QList<QPair<QAction*, QRect>>> clickableActionMap;
524531
QAction *pressedAction = nullptr;
525532
QList<QPointer<QWidget>> lastWidgets;
@@ -1176,9 +1183,9 @@ QSize DStyledItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QM
11761183
const QListView * lv = qobject_cast<const QListView*>(option.widget);
11771184
if (lv) {
11781185
if (lv->flow() == QListView::LeftToRight) {
1179-
size.rwidth() += d->itemSpacing;
1186+
size.rwidth() += d->spacing();
11801187
} else {
1181-
size.rheight() += d->itemSpacing;
1188+
size.rheight() += d->spacing();
11821189
}
11831190
}
11841191

@@ -1353,9 +1360,9 @@ void DStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, const QM
13531360
const QListView * lv = qobject_cast<const QListView*>(option->widget);
13541361
if (lv) {
13551362
if (lv->flow() == QListView::LeftToRight) {
1356-
option->rect.adjust(0, 0, 0 - d->itemSpacing, 0);
1363+
option->rect.adjust(0, 0, 0 - d->spacing(), 0);
13571364
} else {
1358-
option->rect.adjust(0, 0, 0, 0 - d->itemSpacing);
1365+
option->rect.adjust(0, 0, 0, 0 - d->spacing());
13591366
}
13601367
if (lv->window() && lv->window()->isActiveWindow()) {
13611368
option->state |= QStyle::State_Active;

0 commit comments

Comments
 (0)