Results 1 to 1 of 1

Thread: QT5 (Python) - Get top index parent in a recursive map

  1. #1
    Join Date
    Feb 2021
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QT5 (Python) - Get top index parent in a recursive map

    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:


    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()
    Last edited by peshmerga; 23rd February 2021 at 22:51.

Similar Threads

  1. Replies: 1
    Last Post: 30th January 2017, 12:42
  2. Replies: 0
    Last Post: 7th January 2017, 01:09
  3. Embedding PyQt4 into an Application running Python via Boost::Python
    By GreyHound in forum Installation and Deployment
    Replies: 1
    Last Post: 6th February 2012, 07:48
  4. Replies: 0
    Last Post: 8th April 2011, 21:10
  5. Obtain index of child's parent
    By webquinty in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2009, 12:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.