久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 QML PathView 中設置根索引

SetRootIndex in QML PathView(在 QML PathView 中設置根索引)
本文介紹了在 QML PathView 中設置根索引的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 QML PathView 來顯示我的模型.這樣的模型繼承自 QStandardItemModel 并具有兩個級別的數據(父項和子項).我需要在 PathView 中顯示模型的第二級,即選定父級的所有子級.使用 QAbstractItemView 這個結果可以通過使用來實現setRootIndex 函數.如何使用 PathView 獲得相同的結果?

I'm using a QML PathView to show my model. Such a model inherits from QStandardItemModel and has two levels of data (parent items and child items). I need to show the second level of the model in the PathView, i.e. all the children of a selected parent. Using a QAbstractItemView this result can be achieve by using the setRootIndex function. How can I achieve the same result with a PathView?

有人可以幫我嗎?提前致謝.

Can someone help me? Thanks in advance.

這是一個模型示例:

newPetModel::newPetModel()
{
...
 fillModel();
}
...
void newPetModel::fillModel()
{
 QStandardItem* rootItem = invisibleRootItem();
 // groups
 QStandardItem* GroupAnimals = new QStandardItem();
 rootItem->setChild(rootItem->rowCount(), GroupAnimals);
 GroupAnimals->setData(QString("Animals"),nameRole);

 QStandardItem* GroupPlants = new QStandardItem();
 rootItem->setChild(rootItem->rowCount(), GroupPlants);
 GroupPlants->setData(QString("Plants"),nameRole);

 QStandardItem* GroupInsects = new QStandardItem();
 rootItem->setChild(rootItem->rowCount(), GroupInsects);
 GroupInsects->setData(QString("Insects"),nameRole);
 // items
 QStandardItem* Cat = new QStandardItem();
 GroupAnimals->setChild(GroupAnimals->rowCount(), Cat);
 Cat->setData(QString("Cat"),nameRole);
 Cat->setData(QString("qrc:/cat.jpg"),imgRole);

 QStandardItem* Dog = new QStandardItem();
 GroupAnimals->setChild(GroupAnimals->rowCount(), Dog);
 Dog->setData(QString("Dog"),nameRole);
 Dog->setData("qrc:/dog.jpg",imgRole);`enter code here`
 //-----
 QStandardItem* Peas = new QStandardItem();
 GroupPlants->setChild(GroupPlants->rowCount(), Peas);
 Peas->setData(QString("Peas"),nameRole);
 Peas->setData("qrc:/peas.jpg",imgRole);
 //-----
 QStandardItem* Spider = new QStandardItem();
 GroupInsects->setChild(GroupInsects->rowCount(), Spider);
 Spider->setData(QString("Spider"),nameRole);
 Spider->setData("qrc:/peas.jpg",imgRole);

 QStandardItem* Fly = new QStandardItem();
 GroupInsects->setChild(GroupInsects->rowCount(), Fly);
 Fly->setData(QString("Fly"),nameRole);
 Fly->setData("qrc:/fly.jpg",imgRole);
}

推薦答案

QML 適用于列表模型,正如您在您的案例中所見.但是,使用 DelegateModel.引用文檔:

QML works with list models, as you have seen also in your case. However, this limitation can be easily overcome by using DelegateModel. Quoting the documentation:

通常不需要創建 DelegateModel.但是,當 QAbstractItemModel 子類用作模型時,它對于操作和訪問模型索引很有用.此外,DelegateModel 與 Package 一起使用以向多個視圖提供委托,并與 DelegateModelGroup 一起使用以對委托項進行排序和過濾.

It is usually not necessary to create a DelegateModel. However, it can be useful for manipulating and accessing the modelIndex when a QAbstractItemModel subclass is used as the model. Also, DelegateModel is used together with Package to provide delegates to multiple views, and with DelegateModelGroup to sort and filter delegate items.

這種QML類型有一個屬性rootIndex.再次引用文檔:

Such QML type has a property rootIndex. Quoting again the documentation:

QAbstractItemModel 提供了一個分層的數據樹,而 QML 只對列表數據進行操作.rootIndex 允許此模型提供 QAbstractItemModel 中任何節點的子節點.

QAbstractItemModel provides a hierarchical tree of data, whereas QML only operates on list data. rootIndex allows the children of any node in a QAbstractItemModel to be provided by this model.

這是您需要設置(和重置)的屬性,如鏈接文檔示例中所述.請注意,通過使用 DelegateModel,不應定義 PathView 中的委托.一個工作示例(visualdatamodel/slideshow.qml)在路徑下的標準框架分發中可用:

This is the property you need to set (and reset), as described in the example of the linked documentation. Note that by using DelegateModel the delegate in your PathView should not be defined. A working example (visualdatamodel/slideshow.qml) is available in the standard framework distribution under the path:

Qt/QtXXX/Examples/Qt-5.4/quick/views

最后注意 DelegateModelVisualDataModel 經常以可互換的方式使用,因為

Finally note that DelegateModel and VisualDataModel are often used in an interchangeable way since

由于兼容性原因,此類型 (VisualDataModel) 由 Qt QML 模塊提供.相同的實現現在主要用作 Qt QML 模型中的 DelegateModel 模塊.

This type (VisualDataModel) is provided by the Qt QML module due to compatibility reasons. The same implementation is now primarily available as DelegateModel in the Qt QML Models module.

這篇關于在 QML PathView 中設置根索引的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 99精品网 | 成人精品在线观看 | 国产激情在线播放 | 91黄色片免费看 | 999久久 | 久久视频精品 | 成人一区二区三区在线观看 | 黑人巨大精品欧美黑白配亚洲 | 精品一区二区电影 | 亚洲 欧美 综合 | 日韩和的一区二在线 | 亚洲视频中文字幕 | 久草成人网 | 亚洲福利在线观看 | 成人福利电影 | 精品免费视频 | 人人爱干 | 一级片在线观看 | 天天草天天干天天 | 涩色视频在线观看 | 欧美一区二区三区四区视频 | 特黄色一级毛片 | 日韩欧美国产精品 | 亚洲精品第一国产综合野 | 特黄色一级毛片 | 亚洲精品电影网在线观看 | 久久亚洲欧美日韩精品专区 | 欧美中文在线 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 | 国产精品一级 | 91精品国产美女在线观看 | 国产日韩一区二区三区 | 天天干天天玩天天操 | 久久久久久国产精品 | www.日韩高清 | 成人免费视频网站在线观看 | 91污在线 | 日韩欧美大片在线观看 | 精品视频99 | 成av在线| 一区二区欧美在线 |