为树视图创建Qt模型 [英] Creating Qt models for tree views
问题描述
我在Qt中编写一个应用程序(使用C ++),我需要在树视图中表示一个对象结构。这样做的一个方法是为此创建一个模型,但是我在阅读有关主题的Qt文档后仍然很困惑。
I'm writing an application in Qt (with C++) and I need to represent an object structure in a tree view. One of the ways to do this is to create a model for this, but I'm still quite confused after reading the Qt documentation about the subject.
结构我有很简单 - 有一个项目
对象在 std中保存
容器。这些任务也可以保存子任务。任务
:vector
The "structure" I have is pretty simple - there's a Project
object that holds Task
objects in a std::vector
container. These tasks can also hold child tasks.
我已经写了方法来读取&使用Qt的XML类将这些项目写入/从XML文件中。
I've already written methods to read & write these projects to/from XML files using Qt's XML classes.
从头开始创建模型还有更多文档或推荐阅读吗?
Is there any more documentation or "recommended reading" for creating models from scratch? How do you recommend I start implementing this?
推荐答案
QTreeView
newbies ,主要的挑战是理解 index()
和 parent()
。我之前写过一篇文章:
For QTreeView
newbies, the main challenge is with understanding index()
and parent()
. I have written an article about this a while ago:
http: //www.hardcoded.net/articles/using_qtreeview_with_qabstractitemmodel.htm
示例代码是Python,但原则保持不变。
The example code is in Python, but the principles stay the same.
这篇关于为树视图创建Qt模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!