I cannot find any method to get the size, depth, and number of branches of a QTreeView.
I do not mean the size of its graphical representation, but the size of the data stored in the tree.

有帮助吗?

解决方案

You should work with data model, not with view.

To get number of root branches you should use rowColumn( QModelIndex() ) method.

To get depth of any index (item) you should pick up parent index, untill it stay valid. Pseudo-code:

QModelIndex index = /*your item*/;
int depth = 0;
while ( index.parent().isValid() )
{
  index = index.parent();
  depth++;
}
qDebug() << depth;

It is not clear, what you mean by "size" of item? Is it length of text data? You should understand, that it depends on your implementation of data model. Because each item may have a lot of roles.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top