Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Nested QML Menu from nested QStandardItemModel

Nested QML Menu from nested QStandardItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 177 Views
  • 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.
  • P Offline
    P Offline
    PavloPonomarov
    wrote on 7 Sept 2020, 08:59 last edited by PavloPonomarov 9 Jul 2020, 09:24
    #1

    Hello. I have a nested model subclassed from QStandardItemModel and filled like this:

    /*----MyModel.cpp----*/
    for(int row = 0; row < 10; row++){
      setData(index(row,0), "Item"+QString::number(row), Name);
      setData(index(row,0), 0, Value);
      setData(index(row,0), "description of item"+QString::number(row), Description);
      QStandardItem *item = itemFromIndex(index(row,0));
      for(int i = 0; i < 10; i++){
        QStandardItem *subitem = new QStandardItem;
        subitem->setData("SubItem"+QString::number(i), Name);
        subitem->setData(0, Value);
        subitem->setData("Description of subItem"+QString::number(i), Description);
        item->appendRow(subitem);
      }
    }
    

    So, to create a Menu from this model I use Instantiator:

    import MyModel 1.0 //it is registered in main.cpp
    
    MyModel{
       id:myModel
    }
    
    Menu{
      id: topMenu
      title: "Example"
      Instantiator{
         model: myModel
         onObjectRemoved: topMenu.removeItem( object )
         delegate: Component{
             Loader:{
                 id: loader
                 onStatusChanged: if (status == Loader.Ready) {
                                   topMenu.insertMenu( index, item );
                                   loader.item.itemModel = model;
                                  }
                  source: "SubMenuLoader.qml"
             }
         }
      }
    }
    

    My problem is that the model I pass to SubMenuLoader.qml is QQmlDMAbstractItemModelData , which means when I create the Instantiator in SubMenuLoader.qml I will only have the current item, there is no property or method to get children of this model item in QML. I also didn't manage to expose items children from C++, because QML won't understand QList<QStandardItem*>. Even after I declared it as metatype it turns into [QVariant(QStandardItem*, ), QVariant(QStandardItem*, ) ...(and so on)]

    1 Reply Last reply
    0

    1/1

    7 Sept 2020, 08:59

    • Login

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