PDA

View Full Version : setting width of QTreeView branch indicator



borune
22nd May 2018, 11:46
Hi folks!

I need to change width of branch indicator of QTreeView, but i cannot find corresponding parameter in QStyle class.

https://wmpics.pics/di-3W5P.png

I've tried to reimplement all virtual methods in QCommonStyle class which return int, QSize or QRect but the width of branch indicator is always 20.


void drawPrimitive(PrimitiveElement elem, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const
{
if (elem == PE_IndicatorBranch)
if (option->state & State_Children) {
const int width = option->rect.width(); // width is always 20
painter->setPen(QPen(Qt::red));
painter->drawRect(option->rect);
}
}https://wmpics.pics/di-7K83.png

I know that it seems to be possible to do using stylesheets, but i need to do that in styles, no stylesheets.
How could i resize this indicator?

ChristianEhrlicher
27th May 2018, 09:47
I would take a look at http://doc.qt.io/qt-5/qtreeview.html#indentation-prop