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. detect whether collapsed node has selected child node

detect whether collapsed node has selected child node

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 428 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by user4592357
    #1

    when a node in my tree view is collapsed, i emit a signal:

    void Tree::onNodeCollapsed(const QModelIndex &index)
    {
    	// get the collapsed node
    	auto pNode = static_cast<TreeNode *>(index.internalPointer());
    
    	// execute collapse routine
    	pNode->onCollapsed();
    
    	// update the model
    	getTreeModel()->updateModel();
    
    	// inform about node collapse in tree view
    	emit nodeCollapsed(pNode);
    }
    

    later, in a slot:

    void SomeObject::onTreeNodeCollapsed(TreeNode *pNode)
    {
        if (pNode has a selected child)
        {
            // 
        }
        else
        {
            //
        }
    }
    

    how can i determine this?

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

      Hi
      Seems you are using a custom model so just guessing/asking.
      Well cant u ask the selected index,
      what its parent is and then compare
      the parent TreeNode with the pNode ?

      U 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        Seems you are using a custom model so just guessing/asking.
        Well cant u ask the selected index,
        what its parent is and then compare
        the parent TreeNode with the pNode ?

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @mrjj
        ah right. an then do this recursively for the outer levels

        mrjjM 1 Reply Last reply
        0
        • U user4592357

          @mrjj
          ah right. an then do this recursively for the outer levels

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @user4592357
          Hi
          Yes if those are parentless.
          If you dont have millions of items in the model, should be fine.

          U 1 Reply Last reply
          1
          • mrjjM mrjj

            @user4592357
            Hi
            Yes if those are parentless.
            If you dont have millions of items in the model, should be fine.

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @mrjj
            my bad, i'm noticing only now. my question was not about selected node, but rather a collapsed one. how can i know whether the collapsed node has selected child nodes?

            mrjjM 1 Reply Last reply
            0
            • U user4592357

              @mrjj
              my bad, i'm noticing only now. my question was not about selected node, but rather a collapsed one. how can i know whether the collapsed node has selected child nodes?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357
              Well if the current selected index's parents is the
              collapsed node then it has. else not.

              1 Reply Last reply
              1

              • Login

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