Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set root index in PathView
Forum Updated to NodeBB v4.3 + New Features

Set root index in PathView

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 757 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a_stolbov
    wrote on 18 Dec 2014, 13:33 last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      a_stolbov
      wrote on 29 Dec 2014, 12:53 last edited by
      #2

      Answer to my question is "QML DelegateModel":http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved