Use a style proxy setting SH_ItemView_ShowDecorationSelected to fill

* This still isn't perfect with some custom style stuff but it's next
  to impossible to get working right. In theory we should manually
  draw PE_PanelItemViewItem in the gap in drawRow() or so to make sure
  we also draw any on-hover highlight over objects, but that doesn't
  seem to work.
This commit is contained in:
baldurk
2017-06-01 18:28:13 +01:00
parent f0116c4c08
commit 49243c0878
2 changed files with 20 additions and 20 deletions
@@ -24,6 +24,19 @@
#include "RDTreeView.h"
#include <QPainter>
#include <QProxyStyle>
class RDTreeViewtyleProxy : public QProxyStyle
{
public:
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0,
QStyleHintReturn *returnData = 0) const
{
if(hint == QStyle::SH_ItemView_ShowDecorationSelected)
return 1;
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
};
RDTreeViewDelegate::RDTreeViewDelegate(RDTreeView *view) : QStyledItemDelegate(view), m_View(view)
{
@@ -50,6 +63,10 @@ QSize RDTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
RDTreeView::RDTreeView(QWidget *parent) : QTreeView(NULL)
{
setItemDelegate(new RDTreeViewDelegate(this));
// set a proxy style that does nothing but return true for
// QStyle::SH_ItemView_ShowDecorationSelected styleHint.
setStyle(new RDTreeViewtyleProxy);
}
void RDTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &options,
+3 -20
View File
@@ -725,27 +725,10 @@ void RDTreeWidget::drawBranches(QPainter *painter, const QRect &rect, const QMod
}
// fill in the background behind the lines for the whole row, since by default it doesn't show up
// behind the tree lines. There's SH_ItemView_ShowDecorationSelected which controls that for the
// selection highlight but that requires a proxy style and there's no equivalent for the
// background colour.
//
// Instead we just manually fill the background colour, and handle the highlight colour when
// appropriate.
// behind the tree lines.
QRect allLinesRect(rect.left(), rect.top(), rect.left() + parents.count() * indentation() + 1,
rect.height());
if(selectionModel()->isSelected(index))
{
QPalette::ColorGroup group = QPalette::Normal;
if(!isEnabled())
group = QPalette::Disabled;
else if(!hasFocus())
group = QPalette::Inactive;
painter->fillRect(allLinesRect, palette().brush(group, QPalette::Highlight));
}
else if(item->m_back != QBrush())
QRect allLinesRect(rect.left(), rect.top(), (parents.count() + 1) * indentation(), rect.height());
if(!selectionModel()->isSelected(index) && item->m_back != QBrush())
{
painter->fillRect(allLinesRect, item->m_back);
}