PDA

View Full Version : QT5 (Python) - Get top index parent in a recursive map



peshmerga
23rd February 2021, 21:51
Hi,

I've with no avail been trying for hours to get the top index parent of a child which has been selected.
What I'm doing:
https://puu.sh/Hjv4O/8f2f9d4a1c.png

So when you double click ad1-server for example you send the QModel to the function and you can simply do QModel.data() and it returns 'ad1-server'.

Now ad1-server has variables of its own and when you click on that variable you have to now do QModel.parent().data() to get it to return 'ad1-server' again.

Now the variables inside of ad1-server also has variables so when you click on that QModel.parent() will now return the previous parent variable instead of ad1-server and I have been trying with different methods to get it to work with no avail.

How do I get the selected variables Root parent data, for me it is an impossible task at this point.

I tried this method:
self.treeView.selectedIndexes()[0].model().itemFromIndex(val).index(0,0).data()

But this one returns the utter root top item not the root node of the selected item.

Added after 35 minutes:

So I solved this by doing it in a while loop:

root = val.parent()
while(root.parent().data() != None):
root = root.parent()