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:
parent
5ff6acd422
commit
59f04384be
@ -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");
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user