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. Single QTreeView with few QStandardItemModel
Forum Updated to NodeBB v4.3 + New Features

Single QTreeView with few QStandardItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 454 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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by Please_Help_me_D
    #1

    Hi,

    I plan to do the following.
    There is a QTreeView and let say 2 (two) QStandardItemModel.
    User can only see any of these models but only one at a time.
    These models should be equal by the content but may be different by checkbox status.
    As user can add items, delete, rename, toggle checkboxes I need to process such things with both models. If for example user add item to one model then I need somehow to add clone of this item to another model. The same should be done with deleting and renaming except checkbox toggle.

    So how would you recommend me to do this?
    I can see two ways:

    1. use QStandardItemModel::itemChanged(QStandardItem *item)
    2. write code for adding/deleting/renaming items in loop for models (iterate through models and make the same changes with each of them)

    I would prefer the first one (with signal) but I think it is more complicated because items can have children and when I tried to do this (yesterday) ut without success. Can't understand how this signal works with children of item. Also I need to connect this signal with each model and when user rename item then this model changes and the signal is emit, then the second model is changed and the signal is emit again and this would generate an infinite loop probably...

    But iterating through models shouldn't be such difficult beacause writing code for adding/deleting/renaming items of one model should be difficult to populate this code on other models through loop.

    Maybe somebody has experience how to do this in the best way?

    JonBJ 1 Reply Last reply
    0
    • Please_Help_me_DP Please_Help_me_D

      Hi,

      I plan to do the following.
      There is a QTreeView and let say 2 (two) QStandardItemModel.
      User can only see any of these models but only one at a time.
      These models should be equal by the content but may be different by checkbox status.
      As user can add items, delete, rename, toggle checkboxes I need to process such things with both models. If for example user add item to one model then I need somehow to add clone of this item to another model. The same should be done with deleting and renaming except checkbox toggle.

      So how would you recommend me to do this?
      I can see two ways:

      1. use QStandardItemModel::itemChanged(QStandardItem *item)
      2. write code for adding/deleting/renaming items in loop for models (iterate through models and make the same changes with each of them)

      I would prefer the first one (with signal) but I think it is more complicated because items can have children and when I tried to do this (yesterday) ut without success. Can't understand how this signal works with children of item. Also I need to connect this signal with each model and when user rename item then this model changes and the signal is emit, then the second model is changed and the signal is emit again and this would generate an infinite loop probably...

      But iterating through models shouldn't be such difficult beacause writing code for adding/deleting/renaming items of one model should be difficult to populate this code on other models through loop.

      Maybe somebody has experience how to do this in the best way?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Please_Help_me_D said in Single QTreeView with few QStandardItemModel:

      These models should be equal by the content but may be different by checkbox status.

      If that is really the case, you certainly don't want to be arranging for two separate models with one updating the other. Look at using a class inheriting from QAbstractProxyModel as your way of managing the separate models off the same fundamental data. Views can still act off proxy models.

      Please_Help_me_DP 1 Reply Last reply
      1
      • JonBJ JonB

        @Please_Help_me_D said in Single QTreeView with few QStandardItemModel:

        These models should be equal by the content but may be different by checkbox status.

        If that is really the case, you certainly don't want to be arranging for two separate models with one updating the other. Look at using a class inheriting from QAbstractProxyModel as your way of managing the separate models off the same fundamental data. Views can still act off proxy models.

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by
        #3

        @JonB thank you!
        I'm I right that I should fill only one QStandardItemModel and based on it create as many QAbstractProxyModel as I need?

        JonBJ 1 Reply Last reply
        0
        • Please_Help_me_DP Please_Help_me_D

          @JonB thank you!
          I'm I right that I should fill only one QStandardItemModel and based on it create as many QAbstractProxyModel as I need?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Please_Help_me_D
          That is the sort of thing, yes. I don't know how exactly that relates to your "checkbox difference", but that is the best usual approach.

          1 Reply Last reply
          0
          • Please_Help_me_DP Offline
            Please_Help_me_DP Offline
            Please_Help_me_D
            wrote on last edited by
            #5

            if somebody has idea how to use few proxy models on the one QStandardItemModel in the way that each proxy model has its own cheackstatus of every item, please share the idea

            1 Reply Last reply
            0
            • Please_Help_me_DP Offline
              Please_Help_me_DP Offline
              Please_Help_me_D
              wrote on last edited by
              #6

              I'm trying to use QStandardItemModel with QStandardItem.
              Some of QStandardItem I make QStandardItem::setCheckable(true);
              Then I I have filled with items QStandardItemModel and I use two proxy models with QSortFilterProxyModel::setSourceModel
              When I display those two proxy models in QTreeView I can see those checkable items. But if I change checkStatus in one of those two proxy models then the other this item in other proxy model also changes checkStatus.

              Is there a way to make items checkStatus in proxy models independent from checkStatus of those items in other proxy model? All other properties of items (like title) from different models should be equal.
              I understand that both my proxy models are based on the data from one QStandardItemModel but maybe there is the solution for this?

              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