QTreeViewItem painting extends buttons and child lines / child lines

I use QTreeView and QItemDelegate to override most of the chores. However, the expand / collapse buttons and sibling / child lines are automatically drawn using some other drawing procedure.

What draws them, and how can I control it?

EDIT:

Qt now draws the QTreeView element in the following order:

[Expand button] - [Check box] - [Other tree items]

I want to do this in the following order:

[Checkbox] - [Expand button] - [Other elements of the tree]

The problem is that my whole picture in QItemDelegate is to the right of the Expand button.

+4
source share
2 answers

You can change them using the stylesheet . This is from the QTreeView Customization Example in the style sheet:

QTreeView::branch:has-siblings:!adjoins-item { border-image: url(vline.png) 0; } QTreeView::branch:has-siblings:adjoins-item { border-image: url(branch-more.png) 0; } QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: url(branch-end.png) 0; } QTreeView::branch:has-children:!has-siblings:closed, QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(branch-closed.png); } QTreeView::branch:open:has-children:!has-siblings, QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(branch-open.png); } 

where png file names are the images you want to use.

+1
source

Lines are colored with QTreeView.drawRow, branch icons are expanded in drawBranches. Redo it to do nothing, and you will get rid of any automatically drawn material:

 def drawBranches(self,painter,rect,index): pass 

Unfortunately, simply changing the buttons and checkboxes during drawing will not work, because then clicking on the checkmark brings up the button and vice versa.

+1
source

All Articles