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



  • 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!


  • Qt Champions 2017

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



  • @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!


  • Qt Champions 2017

    @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. :)



  • @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 :- )


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.