久久久久久久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 ()?環形?)
主站蜘蛛池模板: 欧美一区二区三区在线看 | 91热在线| 日韩有码一区 | 国产欧美在线观看 | 亚洲97| 日韩欧美专区 | 国产精品久久久久久久三级 | www.日本在线 | 免费一级毛片 | 成人激情视频在线观看 | 国产综合久久久久久鬼色 | 久久a久久 | 国产熟熟 | 免费日本视频 | 精品欧美黑人一区二区三区 | 一区二区三区网站 | 自拍偷拍第一页 | 日韩欧美在线观看视频 | 国产精品国产自产拍高清 | 欧美成人第一页 | 国产精品自产av一区二区三区 | 在线观看亚洲精品视频 | 久久大陆 | 精品国产乱码一区二区三区a | 亚洲毛片网站 | 婷婷激情在线 | 亚洲精品国产精品国自产在线 | 99热精品在线 | 红桃视频一区二区三区免费 | 国产 日韩 欧美 在线 | 亚洲在线电影 | 久久爱一区 | 精品国产一区久久 | 五月综合激情网 | 亚洲视频免费观看 | 亚洲精品久久久久中文字幕欢迎你 | www亚洲免费国内精品 | 亚洲综合日韩精品欧美综合区 | 精品国产久 | 久久国产亚洲 | 中文字幕在线不卡播放 |