QTreeView Fraction Drop Indicator

I need to implement rows moving using drag-n-drop in a QTreeView and show a progress bar between the lines. I am wondering if there is a way to override the indicator drawing, so it is displayed for all hierarchy levels only between the lines (and not the rectangle around the element), the line should be as wide as the whole line (and not as one column).

+4
source share
1 answer

You can use the modyfing style to draw a widget. My attempt seemed to work well, but it tricked the qt style system a bit, so I can’t guarantee that it will work under all possible styles on all platforms. So here it is:

class myViewStyle: public QProxyStyle{ public: myViewStyle(QStyle* style = 0); void drawPrimitive ( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0 ) const; }; myViewStyle::myViewStyle(QStyle* style) :QProxyStyle(style) {} void myViewStyle::drawPrimitive ( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget) const{ if (element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull()){ QStyleOption opt(*option); opt.rect.setLeft(0); if (widget) opt.rect.setRight(widget->width()); QProxyStyle::drawPrimitive(element, &opt, painter, widget); return; } QProxyStyle::drawPrimitive(element, option, painter, widget); } myView::myView(QWidget *parent) : QTreeView(parent) { setStyle(new myViewStyle(style())); } 
+9
source

All Articles