[Qt-jambi-interest] How NOT to draw lines connecting parent nodes and children nodes in QTreeView?

Eskil Abrahamsen Blomfeldt eblomfel at trolltech.com
Thu Jul 24 09:11:35 CEST 2008


hAmmeRoL wrote:
> I wanted the QTreeView in my application not to draw lines connecting 
> parent nodes and children nodes. But I failed to find any methods 
> provided by QTreeView and wondered how it should be done?
>
> Anyone has an idea about how to get this done?

The indicator branch is painted by the current style. One way of making 
sure it's not shown is by overriding the style's drawPrimitive() method 
and returning without painting anything when the selected element is 
PE_IndicatorBranch:

    @Override
    public void drawPrimitive(PrimitiveElement element, QStyleOption 
option, QPainter painter, QWidget widget) {
        if (element != PrimitiveElement.PE_IndicatorBranch)
            super.drawPrimitive(element, option, painter, widget);   
    }

A simpler solution might be to override the painting of the branch in 
the stylesheet and have it do nothing, with something like this:

    QTreeView myTreeView = new QTreeView();
    myTreeView.setStyleSheet("::branch { background: transparent;  }");


> How to customize the treeview in order to show three different icons 
> and two different font types together in a same node. Currently, there 
> are only one icon for each node and the text in a node is rendering 
> using the same font.

You will need to extend QTreeView and implement this behavior yourself.

-- Eskil



More information about the Qt-jambi-interest mailing list