From 6d5d12cbcb4433b4dc022ac05f876b6f5dc94f17 Mon Sep 17 00:00:00 2001 From: ssk-wh Date: Mon, 8 Apr 2024 15:19:46 +0800 Subject: [PATCH] fix: fix the problem of text position in dstyleditemdelegate as title log: as title issue: https://github.com/linuxdeepin/developer-center/issues/7673 --- include/widgets/dlistview.h | 2 ++ src/widgets/dlistview.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/widgets/dlistview.h b/include/widgets/dlistview.h index 47851aa06..f3d4d0c79 100644 --- a/include/widgets/dlistview.h +++ b/include/widgets/dlistview.h @@ -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; diff --git a/src/widgets/dlistview.cpp b/src/widgets/dlistview.cpp index 2a8db9777..16672ba05 100644 --- a/src/widgets/dlistview.cpp +++ b/src/widgets/dlistview.cpp @@ -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(); @@ -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)