计数显示QTREEVIEW的(可见)行

发布于 2025-01-28 03:00:24 字数 733 浏览 3 评论 0 原文

我发现这个问题

我也在其他地方搜索。

情况是(从所有的根本项目崩溃开始)我的代码通过树的迭代迭代,扩展了这些项目与某个标准相匹配的项目的父母。

我只想在该过程结束时找到 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 QTableViews. With the latter it appears that it possible to use table_view.verticalHeader().count(). But a QTreeView doesn't have the method verticalHeader.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2025-02-04 03:00:24

qtreeview提供 indexabove() indexbelow(indexbelow() 功能,后者:

返回 index 的项目的模型索引。

    def count_showing_rows(self):
        count = 0
        index = self.model().index(0, 0)
        while index.isValid():
            count += 1
            index = self.indexBelow(index)
        return count

QTreeView provides the indexAbove() and indexBelow() functions, and the latter:

Returns the model index of the item below index.

    def count_showing_rows(self):
        count = 0
        index = self.model().index(0, 0)
        while index.isValid():
            count += 1
            index = self.indexBelow(index)
        return count
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文