Skip to content

Commit

Permalink
Use hack to customise expander colour in treeview branches. Closes #3319
Browse files Browse the repository at this point in the history
  • Loading branch information
baldurk committed May 17, 2024
1 parent 1019b7f commit 1ad23f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 6 additions & 10 deletions qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 11 additions & 1 deletion qrenderdoc/Widgets/Extended/RDTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 1ad23f6

Please sign in to comment.