qt model view 编程总结

看不见的root的 QModelIndex() 是 无效的

list 和table 的index 函数中的parent参数就只要 root QModelIndex 就可以,因为没有层级概念

  • Model indexes give views and delegates information about the location of items provided by models in a way that is independent of any underlying data structures.
  • Items are referred to by their row and column numbers, and by the model index of their parent items.
  • Model indexes are constructed by models at the request of other components, such as views and delegates.
  • If a valid model index is specified for the parent item when an index is requested using index(), the index returned refers to an item beneath that parent item in the model. The index obtained refers to a child of that item.
  • If an invalid model index is specified for the parent item when an index is requested using index(), the index returned refers to a top-level item in the model.
  • The role distinguishes between the different kinds of data associated with an item.
  • The dimensions of a model can be found using rowCount() and columnCount(). These functions generally require a parent model index to be specified.
  • Model indexes are used to access items in the model. The row, column, and parent model index are needed to specify the item.
  • To access top-level items in a model, specify a null model index as the parent index with QModelIndex().
  • Items contain data for different roles. To obtain the data for a particular role, both the model index and the role must be supplied to the model.
 
原文地址:https://www.cnblogs.com/cute/p/4453130.html