Skip to content

Commit

Permalink
fix: fix the problem of text position in dstyleditemdelegate
Browse files Browse the repository at this point in the history
as title

log: as title
issue: linuxdeepin/developer-center#7673
  • Loading branch information
ssk-wh committed Apr 8, 2024
1 parent c1420ba commit 6d5d12c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/widgets/dlistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public Q_SLOTS:

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStyleOptionViewItem viewOptions() const override;
#else
void initViewItemOption(QStyleOptionViewItem *option) const override;
#endif
virtual QModelIndex moveCursor(CursorAction cursorAction,
Qt::KeyboardModifiers modifiers) override;
Expand Down
16 changes: 15 additions & 1 deletion src/widgets/dlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ bool DListView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger tr
return tmp;
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) //TODO: error Maybe
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStyleOptionViewItem DListView::viewOptions() const
{
QStyleOptionViewItem item = QListView::viewOptions();
Expand All @@ -936,6 +936,20 @@ QStyleOptionViewItem DListView::viewOptions() const

return item;
}
#else
/*!
\reimp
*/
void DListView::initViewItemOption(QStyleOptionViewItem *option) const
{
QListView::initViewItemOption(option);
option->showDecorationSelected = true;
// 列表项不会变为Inactive状态
option->state |= QStyle::State_Active;
if (viewMode() == QListView::ListMode) {
option->decorationAlignment = Qt::AlignVCenter;
}
}
#endif

QModelIndex DListView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
Expand Down

0 comments on commit 6d5d12c

Please sign in to comment.