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. TreeModel, remove an item pointed by an index

TreeModel, remove an item pointed by an index

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

    Hi all.

    I use the stuff described here that basically is a subclass of QAbstractItemModel

    My question is very simple but I feel I tried everything.

    How can I erase an item of a TreeModel if I have an index pointing to it?

        QModelIndex cycleModelIndex;
        QModelIndex cycleModelIndexChild;
        cycleModelIndex = model->index(2,0);
    

    and I want to kill the item pointed by cycleModelIndex...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Isn't that what

      TreeNode * TreeModel ::nodeForIndex(const QModelIndex &index) const;
      void TreeModel ::removeNode(TreeNode *node);
      

      are for ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      VRoninV 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Isn't that what

        TreeNode * TreeModel ::nodeForIndex(const QModelIndex &index) const;
        void TreeModel ::removeNode(TreeNode *node);
        

        are for ?

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @SGaist Not really. They are only if your tree has only 1 column (i.e. that method removes the entire row). since the linked model only supports 1 role, however, you can just set the Qt::DisplayRole data of the index to QVariant() (you'll probably have to reimplement setData in the model to achieve this)

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • P Offline
          P Offline
          Patou355
          wrote on last edited by
          #4
          This post is deleted!
          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