QProxyStyle & PE_IndicatorBranch Drawing logic
-
Hello
I'm trying to understand how to draw my decorators... the line next to the item in QTreeView/etc
handle all the cases of decorator that cab happen, item, multi item, child items, etc etc, say this >
I want to for example, not draw circle on 1st decorator on left if there child on right and so on.
Draw ending line, starting line, corner line for children, etc etc.I tried with
const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(option);But the index is always invalid.
How do I know which decorator I'm drawing, leftc/right/right/right etc etc if there multi child logic/etc /etc?Any guides/hints would be great!
Regards
Dariusz -
Ok figured it out, its suprisingly simple...
https://doc.qt.io/qt-6/style-reference.html#tree-branch-indicatorsint xMid = rect.center().x(); int yMid = rect.center().y(); int dotRadius = 4; QRect indicatorRect(xMid - 5, yMid - 5, 10, 10); const auto state = viewOpt->state; if (state & State_Children) { painter->setPen(Qt::red); painter->drawRect(indicatorRect); if (state & State_Open) { painter->setPen(Qt::blue); painter->drawEllipse(QPoint(xMid, yMid), dotRadius, dotRadius); } else { painter->setPen(QColor(0, 0, 0)); painter->drawLine(0, yMid, rect.right(), yMid); } } if (state & State_Item) { painter->setPen(QColor(0, 150, 0)); painter->drawEllipse(QPoint(xMid, yMid), dotRadius / 2, dotRadius / 2); if (state & State_Sibling) { painter->drawLine(xMid, rect.top(), xMid, rect.bottom()); } else { painter->drawLine(xMid, rect.top(), xMid, yMid); painter->drawLine(xMid, yMid, rect.right(), yMid); } } else { painter->setPen(QPen(QColor(0, 150, 150), 4)); if (state & State_Sibling) { painter->drawLine(xMid, rect.top(), xMid, rect.bottom()); } }
-