QTreeView / QAbstractItemModel subtrees in multiple columns

I am working on a subclass of QAbstractItemModel that connects to a QTreeView . It has a recursive structure of the type Name = Value - any index can have its own subtree. This is good on the left side, because almost every kind of tree there works like this. The problem is that sometimes I want a subtree only on the right side - a list of values. Since I have this right now, it looks like it should work, but Qt never calls rowCount() on the right side and never realizes that there should be a subtree.

The solution that I have now is to create a separate model for it and use setIndexWidget so that each time it leads to a separate tree view. This is fine, but I would really like the subtrees to appear on the right without casting tree-like looks everywhere. My model says that there are subtrees, but Qt just doesn't ask for them.

If this is a bit unclear, this is the basic idea of โ€‹โ€‹what I want to achieve:

 - Root | - Name 1 | Value Name 2 | - Compound Value | Sub-value 1 | Sub-value 2 Name 3 | + Compound Value (collapsed) + Name 4 | Value 

Be that as it may, the connection values โ€‹โ€‹will not have + and - next to them, because Qt never calls hasChildren() or rowCount() in this column, although my model will return it yes, there are children if that were set .

If I finally need to give him an idea of โ€‹โ€‹a subtree, that's fine. I just wanted to be sure that at first there would be no better way to do this.

+4
source share
1 answer

I am trying to implement a double tree. Look at yourself, something like

 + a | A + b | + B c | C 

and from what I saw, you can make a space between name 2 and name 3, returning empty data, for example. an empty line named 2, which allows you to have + infront.

So something like this might help

 def data(self, index, role): ... if item.pathdepth() > 3 : return " " ... def flags(self, index) ... if item.pathdepth() > 3 : return Qt.Some_Role but not others ... 

I donโ€™t know enough about roles yet, but you can turn off selection and editing so that custom spaces are not selected.

But I have not developed how to get the tree in the second column.

0
source

Source: https://habr.com/ru/post/1402340/


All Articles