我发现这个问题和。
我也在其他地方搜索。
情况是(从所有的根本项目崩溃开始)我的代码通过树的迭代迭代,扩展了这些项目与某个标准相匹配的项目的父母。
我只想在该过程结束时找到 qtreeview
中显示的行的总数。 nb我使用“显示”而不是“可见”一词,因为这不是关于视口的问题:我希望总的数字显示,假设一个视口足够大,以至于不必创建垂直卷轴。
真的没有简单的方法来实现这一目标吗?例如,计算出来的总孩子,例如计算所有父母的所有孩子,随着他们的扩展,它们会非常复杂:有时,有时,两个兄弟姐妹满足标准,但第二个显然没有。不仅
这样再次扩展后,以计算显示的行。这似乎是为了获得如此简单的信息而荒谬的努力。
请注意,我说的是 qtreeviews
,而不是 qtableView
s。使用后者,似乎可以使用 table_view.verticalheader()。count()
。但是 QTREEVIEW
没有方法 Verticalheader
。
I found this question and this question.
I've also searched elsewhere.
The situation is that (starting with all root item children collapsed) my code iterates through the tree expanding the parents of those items whose data matches a certain criterion.
I just want to find the total number of showing rows displayed in the QTreeView
at the end of that process. NB I use the word "showing" rather than "visible" as this is not a question about viewports: I want the total number showing assuming a viewport large enough not to have to create a vertical scrollbar.
Is there really no simple way to achieve this? Counting the total children displayed by, for example, counting all children of all parents which are expanded in this manner, as they get expanded, would be quite complex: sometimes, for example, two siblings meet the criterion, so the first expands its parent, but the second obviously doesn't. Not only that, but a node located deep in the tree expands not only its own parent, but (if necessary) its grandparent, great-grandparent, etc.
In view of the complexity of the foregoing, another possibility would be to iterate through the tree again, after expanding, in order to count the rows displayed. This seems a ludicrous effort just to get such a simple piece of information.
Please note that I'm talking about QTreeViews
, not QTableView
s. With the latter it appears that it possible to use table_view.verticalHeader().count()
. But a QTreeView
doesn't have the method verticalHeader
.
发布评论
评论(1)
qtreeview提供
indexabove()
indexbelow(indexbelow()
功能,后者:QTreeView provides the
indexAbove()
andindexBelow()
functions, and the latter: