4
votes

I am using a QTreeView and a QItemDelegate to reimplement most of the paint routine. However, the expand/collapse buttons and the sibling/child lines are drawn automatically by some other paint routine.

What is drawing them, and how can I control it?

EDIT:

Right now, Qt draws a QTreeView item in this order:

[Expand button] -- [Checkbox] -- [Rest of treeitem stuff]

I want to draw it in this order:

[Checkbox] -- [Expand button] -- [Rest of treeitem stuff]

The problem is that all my painting in the QItemDelegate is to the right of the Expand Button.

2

2 Answers

1
votes

You can change those using a style sheet. This is from the Customizing QTreeView example in the style sheet reference:

 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 the png filenames are the images you want to use.

1
votes

The rows are painted by QTreeView.drawRow, the branches and expand icons are drawn in drawBranches. Reimplement it to do nothing and you'll get rid of any automatically drawn stuff:

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

Unfortunately simply exchanging the buttons and checkboxes during painting won't work, because then clicks on the checkbox will trigger the button and vice versa.