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. QStandardItemModel & QStandardItem instance 10+ items between 2 models?

QStandardItemModel & QStandardItem instance 10+ items between 2 models?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstandarditemmoqstandarditeminstantiation
4 Posts 3 Posters 890 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    I'm tinkering with idea of instancing data between 2 standardItemModels. Say Model A has 20 nodes, and modelB has 10 nodes. I would like to share the nodes from modelA to modelB, let them be "their own little hierarchy" but if I change their order in modelA I'd like to see the same action happen in modelB... humh I guess I would not be able to parent them anywhere in modelB to native modelB nodes, because that would break everything. But I do wonder... has any1 tried this before?

    Regards
    Dariusz
    TIA

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Not possbile. Model takes the ownership of items when set. So two model cannot own the same item. It will be a big trouble. You can use QSortFilterProxyModel if your interest is share the subset of data to another model.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      2
      • E Offline
        E Offline
        Eeli K
        wrote on last edited by
        #3

        Of course if you inherit abstract model directly and implement your own data handling the data can be anything you want, even shared, provided that you know what you're doing.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dariusz
          wrote on last edited by
          #4

          @dheerendra thanks! I had a feeling that was the case, but QSortFilterProxyModel is a very interesting discovery! I used it a few times but humh... I will look into that more! Thanks! If you have any suggestions/tutorials/read please shoot away, bit lost atm as to what to look for there.

          @Eeli-K Yep, I subclass QAbstractItemModel & created my own treeItem from the ground up so I have full control over these 2 entities. I Extended QtreeView with some "helper" handlers of my data/model but that's it. Did not touch QModelIndex to me its black magic ;- ) Will think about solving that internally somehow. If I were to redirect the read of some widgets, what would I need to extend more? index/data/row functions? Hmm I need to think about it more. Getting some lightbulbs slowly here but I wonder if it's backward. Atm, I'm thinking that each of the virtual functions I had to overload would have to return native model data 1st and once that's done, return the instanced model/items data... uhhh getting complicated humhhhh humhhh humhhhh interesting. Thanks!

          Regards
          Dariusz
          TIA

          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