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. QTreeview - check if selected item is part of selected parent?
Qt 6.11 is out! See what's new in the release blog

QTreeview - check if selected item is part of selected parent?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.1k Views 2 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.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hey

    Does QT offer any out of box check if selected item is part of selected tree?

    Say I have

    -----Parent_A < Selected
    ----------Child_B
    ---------------ChildOfChild_C < Selected
    ---------------ChildOfChild_D

    When I do selectedIndexes() > I'll get 2 entries, how can I then check if the items are in treeSelection? Like I would need to get only Parent_A in my QList and remove ChildOfChild_C.

    I reckon I need to do recursive function for it, but maybe QT offers something out of box?

    Thanks!

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

      Hi
      I never saw any function to tell you that directly and did recursive
      traverse the tree to find parent(s).

      D 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        I never saw any function to tell you that directly and did recursive
        traverse the tree to find parent(s).

        D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        @mrjj said in QTreeview - check if selected item is part of selected parent?:

        Hi
        I never saw any function to tell you that directly and have recursive
        traverse the tree to find parent(s).

        Mmm darn, I thought there was a function for it as that's what drag&drop has to check when dropping items. QT produces the correct result so perhaps there is a different way of doing it, mmmm will keep looking. Thanks!

        mrjjM 1 Reply Last reply
        0
        • D Dariusz

          @mrjj said in QTreeview - check if selected item is part of selected parent?:

          Hi
          I never saw any function to tell you that directly and have recursive
          traverse the tree to find parent(s).

          Mmm darn, I thought there was a function for it as that's what drag&drop has to check when dropping items. QT produces the correct result so perhaps there is a different way of doing it, mmmm will keep looking. Thanks!

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

          @Dariusz
          Yeah maybe it would be interesting to inspect the code for
          drop and see what it calls.

          That said, i have not used Views that much so there is still hope such function exists but just named something that dont spring to eye. :)

          D 1 Reply Last reply
          0
          • mrjjM mrjj

            @Dariusz
            Yeah maybe it would be interesting to inspect the code for
            drop and see what it calls.

            That said, i have not used Views that much so there is still hope such function exists but just named something that dont spring to eye. :)

            D Offline
            D Offline
            Dariusz
            wrote on last edited by Dariusz
            #5

            @mrjj said in QTreeview - check if selected item is part of selected parent?:

            @Dariusz
            Yeah maybe it would be interesting to inspect the code for
            drop and see what it calls.

            That said, i have not used Views that much so there is still hope such function exists but just named something that dont spring to eye. :)

            Yeah, I looked into it buts it's black magic. They use bits& other stuff which I struggle to understand... I think it happens in mimeData and decodeData(or other function that sound similar) No idea. Black magic :- )

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

              Hi,

              AFAIK, @mrjj is right, there's not direct way to get that information from the QItemSelectionModel as it might contain selection information from several views. You could maybe use QModelIndex::sibling to search for that information.

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

              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