qml treeview 图标_QT qml TreeView展示数据结构于界面

本文介绍了如何使用QML的TreeView展示树状结构,重点解析了QAbstractItemModel类及其重要函数的用途,包括数据检索、角色、索引、插入删除操作,并强调了在实现自定义模型时需要注意的事项,如重新实现必要的函数和发出数据改变信号。
摘要由CSDN通过智能技术生成

Class  QAbstractItemModel:

使用QML的TreeView类来展示树状的结构,对应的是QT的Model/View模型。这个model是一个数据模型,要为TreeView提供一个模型,需要定义一个类,该类需要继承自calss QAbstractItemModel,不能直接使用该类。

另外,If you need a model to use with an item view such as QML's List View element or the C++ widgets QListView or QTableView, you should consider subclassing QAbstractListModel or QAbstractTableModel instead of this class.

定义的模型可以是有层次关系的(即有item含有孩子),模型被传递给Views和delegates. 如果模型没有层次关系,那么就指示一个简单的表格,表中的每个元素(item)都有唯一的index,index是 calss QModelIndex的对象,The QModelIndex class is used to locate data in a data model.

11a64e52433f4ac85fa793342475838b.png

模型中的每一个Item对应一个model index, 可以通过QAbstractItemModel::index函数来获取,但是该函数式纯虚函数,需要使用者自己实现,具体实现方法??

Each item has a number of data elements associated with it ,each with its own role, and these elements can be retrieved(检索,取出) by specifying a role (see Qt::ItemDataRole) to the model's data() function. Data for all available roles can be obtained at the same time using theitemData() function.   The roles are used by the view to indicate to the model which type of data it needs(View使用这些roles来告诉模型,自己需要模型的哪一中数据来显示在图形上). ---------- 没大明白,指的是模型中的每一个item都有很多属性吗,然后每一个属性对应着一个唯一的role,说属性的值就相当于说该属性的role的值?

Data for each role is set using a particular Qt::ItemDataRole. Data for individual roles are set individually with setData(), or they can be set for all roles with setItemData().---- Qt::ItemDataRole的作用是设置某个item的某个role对应的值。

Items can be queried with flags() (see Qt::ItemFlag) to see if they can be selected, dragged, or manipulated in other ways.---flags()为虚函数。

If an item has child objects, hasChildren() returns true for the corresponding index.----hasChildren()是虚函数。

The model has a rowCount() and a columnCount() for each level of the hierarchy. Rows and columns can be inserted and removed with insertRows(), insertColumns(), removeRows(), and removeColumns().-----rowCount() and a co

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值