Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved detect whether collapsed node has selected child node

    General and Desktop
    2
    6
    212
    Loading More Posts
    • 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
      user4592357 last edited by user4592357

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • U
          user4592357 @mrjj last edited by

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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @user4592357 last edited by

            @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 Reply Quote 1
            • U
              user4592357 @mrjj last edited by

              @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?

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @user4592357 last edited by

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

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post