QTreeView / QAbstractItemModel - 添加项目并使用 beginInsertRows
我正在基于 QAbstractItemModel 实现我的模型,并将其与 QTreeView 一起使用来显示分层数据。数据存储在 sqlite 表中。
我的问题是添加子节点时应该如何调用 beginInsertRows 。 假设我有一些父节点,它包含 10 个子节点。我想添加新的子节点(在最后)。
我这样做是这样的:
beginInsertRows(parentIndex, currentNodesCount, currentNodesCount);
// actual inserting
endInsertRows()
currentNodesCount 包含值 10,它是该子节点中的行数。 新节点将被放置在第 11 个位置(从 0 开始计数的第 10 个)。
这个逻辑正确吗?
感谢您的帮助。
我还想知道如何使用 beginRemoveRows。
这是正确的吗:
beginRemoveRows(parentIndex, currentRow, currentRow);
// delete record
endRemoveRows();
currentRow 包含已删除节点列表中从 0 开始计数的位置。
I'm implementing my model based on QAbstractItemModel and I'm using it with QTreeView to display hierachical data. Data are stored in sqlite table.
My question is how should I call beginInsertRows when adding subnodes.
Lets say I have some parent node, it contains 10 subnodes. And I want to add new subnode (at the end).
I'm doing it like this:
beginInsertRows(parentIndex, currentNodesCount, currentNodesCount);
// actual inserting
endInsertRows()
currentNodesCount contains value 10 which is the number of rows in this subnode.
The new node will be placed at the 11th position (10th counting from 0).
Is this logic correct ?
Thanks for help.
I'm wondering also about using beginRemoveRows.
Is this correct:
beginRemoveRows(parentIndex, currentRow, currentRow);
// delete record
endRemoveRows();
currentRow contains position in the list of the removed node counting from 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,就是这样。
这是你唯一的问题吗?
Yes that's it.
Was this your only question?