Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top