Set root index in PathView
-
Hi,
I have to show two-level data model in QML PathViews
I have a simple model, child of QStandardItemModel.
@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);
//-----
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);
}
@I export data model to QML context and show it
@...
Component {
id:groupDelegate
...
}
PathView
{
id:mainView
model: petModel
delegate: groupDelegate
...
}
// here must be one more PathView with members of selected group
}@To show second level of data in QAbstractItemView we can use setRootIndex() function. How we can do this in PathView?
Thanks in advance
Anatoly -
Answer to my question is "QML DelegateModel":http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html