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.
Here a model example:
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);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…