From 59f04384be7002b428c581d44249a8407bb8385e Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Sat, 24 Feb 2018 23:50:20 +0300 Subject: [PATCH] #0 [Gui] Paint background for current item for tree-widget --- profiler_gui/arbitrary_value_inspector.cpp | 2 +- profiler_gui/treeview_first_column_delegate.cpp | 13 ++++++++++++- profiler_gui/treeview_first_column_delegate.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/profiler_gui/arbitrary_value_inspector.cpp b/profiler_gui/arbitrary_value_inspector.cpp index 6cc1242..89e6620 100644 --- a/profiler_gui/arbitrary_value_inspector.cpp +++ b/profiler_gui/arbitrary_value_inspector.cpp @@ -1743,7 +1743,7 @@ ArbitraryValuesWidget::ArbitraryValuesWidget(QWidget* _parent) //m_treeWidget->setSortingEnabled(false); m_treeWidget->setColumnCount(int_cast(ArbitraryColumns::Count)); m_treeWidget->setSelectionBehavior(QAbstractItemView::SelectRows); - m_treeWidget->setItemDelegateForColumn(0, new TreeViewFirstColumnItemDelegate(this)); + m_treeWidget->setItemDelegateForColumn(0, new TreeViewFirstColumnItemDelegate(m_treeWidget)); auto headerItem = new QTreeWidgetItem(); headerItem->setText(int_cast(ArbitraryColumns::Type), "Type"); diff --git a/profiler_gui/treeview_first_column_delegate.cpp b/profiler_gui/treeview_first_column_delegate.cpp index 9676835..fdbc8ed 100644 --- a/profiler_gui/treeview_first_column_delegate.cpp +++ b/profiler_gui/treeview_first_column_delegate.cpp @@ -2,10 +2,11 @@ #include #include +#include #include "treeview_first_column_delegate.h" #include "globals.h" -TreeViewFirstColumnItemDelegate::TreeViewFirstColumnItemDelegate(QObject* parent) : QStyledItemDelegate(parent) +TreeViewFirstColumnItemDelegate::TreeViewFirstColumnItemDelegate(QTreeWidget* parent) : QStyledItemDelegate(parent) { } @@ -25,9 +26,19 @@ void TreeViewFirstColumnItemDelegate::paint(QPainter* painter, const QStyleOptio if (bottomLeft.x() > 0) { painter->save(); + + if (static_cast(parent())->currentIndex() == index) + { + // Draw selection background for current item + painter->setBrush(QColor::fromRgba(0xCC98DE98)); + painter->setPen(Qt::NoPen); + painter->drawRect(QRectF(0, option.rect.top(), bottomLeft.x(), option.rect.height())); + } + painter->setBrush(Qt::NoBrush); painter->setPen(::profiler_gui::SYSTEM_BORDER_COLOR); painter->drawLine(QPoint(0, bottomLeft.y()), bottomLeft); + painter->restore(); } } \ No newline at end of file diff --git a/profiler_gui/treeview_first_column_delegate.h b/profiler_gui/treeview_first_column_delegate.h index 30fa5c9..10e1001 100644 --- a/profiler_gui/treeview_first_column_delegate.h +++ b/profiler_gui/treeview_first_column_delegate.h @@ -14,7 +14,7 @@ class TreeViewFirstColumnItemDelegate : public QStyledItemDelegate public: - explicit TreeViewFirstColumnItemDelegate(QObject* parent = nullptr); + explicit TreeViewFirstColumnItemDelegate(class QTreeWidget* parent = nullptr); ~TreeViewFirstColumnItemDelegate() override; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;