Use hack to customise expander colour in treeview branches. Closes #3319

This commit is contained in:
baldurk
2024-05-17 11:41:53 +01:00
parent 1019b7f2cb
commit 1ad23f64ca
2 changed files with 17 additions and 11 deletions
@@ -257,16 +257,12 @@ void RDTweakedNativeStyle::drawPrimitive(PrimitiveElement element, const QStyleO
QColor col = opt->palette.color(QPalette::Text);
if(opt->state & State_MouseOver)
{
QColor highlightCol = opt->palette.color(QPalette::Highlight);
col.setRedF(col.redF() * 0.6 + highlightCol.redF() * 0.4);
col.setGreenF(col.greenF() * 0.6 + highlightCol.greenF() * 0.4);
col.setBlueF(col.blueF() * 0.6 + highlightCol.blueF() * 0.4);
}
p->setPen(QPen(col, 2.0));
// turbo hack to pass desired colour through QTreeView::drawBranches when it can't customise
// the colour and doesn't set the model index to let us look up this data ourselves :(
if(oldPen.widthF() == 1234.5f)
p->setPen(QPen(oldPen.color(), 2.0));
else
p->setPen(QPen(col, 2.0));
QPainterPath path;
+11 -1
View File
@@ -774,10 +774,19 @@ void RDTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModel
opt.rect = allLinesRect;
opt.showDecorationSelected = true;
opt.backgroundBrush = index.data(Qt::BackgroundRole).value<QBrush>();
QColor foreCol = index.data(Qt::ForegroundRole).value<QBrush>().color();
opt.palette.setColor(QPalette::Foreground, foreCol);
opt.palette.setColor(QPalette::Text, foreCol);
style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, this);
QPen oldPen = painter->pen();
if(m_VisibleBranches)
{
// set the desired colour for RDTweakedNativeStyle via a huge hack - see
// RDTweakedNativeStyle::drawPrimitive for QStyle::PE_IndicatorBranch
painter->setPen(QPen(foreCol, 1234.5));
QTreeView::drawBranches(painter, rect, index);
}
else
@@ -804,12 +813,13 @@ void RDTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModel
if(isExpanded(index))
branchopt.state |= QStyle::State_Open;
branchopt.palette = opt.palette;
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchopt, painter, this);
}
// we now iterate from the top-most parent down, moving in from the left
// we draw this after calling into drawBranches() so we paint on top of the built-in lines
QPen oldPen = painter->pen();
while(!parents.isEmpty())
{
parent = parents.pop();