0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 00:31:02 +08:00

#0 [Gui] Paint background for current item for tree-widget

This commit is contained in:
Victor Zarubkin 2018-02-24 23:50:20 +03:00
parent 5ff6acd422
commit 59f04384be
3 changed files with 14 additions and 3 deletions

View File

@ -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");

View File

@ -2,10 +2,11 @@
#include <QPainter>
#include <QPoint>
#include <QTreeWidget>
#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<const QTreeWidget*>(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();
}
}

View File

@ -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;