QTreeWidget insertTopLevelItem - index given not accurately displayed in Tree?

Posted by mleep on Stack Overflow See other posts from Stack Overflow or by mleep
Published on 2010-03-25T23:54:41Z Indexed on 2010/03/26 18:13 UTC
Read the original article Hit count: 561

Filed under:
|
|
|
|

I am unable to properly insert a QTreeWidgetItem at a specific index, in this case I am removing all QTreeWidgetItems from the tree, doing a custom sort on their Date Objects and then inserting them back into the QTreeWidget.

However, upon inserting (even one at a time) the QTreeWidgetItem is not inserted into the correct place.

The code below prints out:

index 0: 0

index 0: 1 index 1: 0

index 0: 2 index 1: 1 index 2: 0

index 0: 3 index 1: 2 index 2: 0 index 3: 1

index 0: 4 index 1: 2 index 2: 0 index 3: 1 index 4: 3

print 'index 0: ', self.indexOfTopLevelItem(childrenList[0])

self.insertTopLevelItem(0, childrenList[1])

print 'index 0: ', self.indexOfTopLevelItem(childrenList[0]), ' index 1: ',\
    self.indexOfTopLevelItem(childrenList[1])

self.insertTopLevelItem(0, childrenList[2])

print 'index 0: ', self.indexOfTopLevelItem(childrenList[0]), ' index 1: ',\
    self.indexOfTopLevelItem(childrenList[1]), ' index 2: ', \
    self.indexOfTopLevelItem(childrenList[2])

self.insertTopLevelItem(0, childrenList[3])

print 'index 0: ', self.indexOfTopLevelItem(childrenList[0]), ' index 1: ',\
    self.indexOfTopLevelItem(childrenList[1]), ' index 2: ',\
    self.indexOfTopLevelItem(childrenList[2]), 'index 3: ',\
    self.indexOfTopLevelItem(childrenList[3])

self.insertTopLevelItem(0, childrenList[4])

print 'index 0: ', self.indexOfTopLevelItem(childrenList[0]),\
    ' index 1: ', self.indexOfTopLevelItem(childrenList[1]),\
    ' index 2: ', self.indexOfTopLevelItem(childrenList[2]),\
    'index 3: ', self.indexOfTopLevelItem(childrenList[3]),\
    'index 4: ', self.indexOfTopLevelItem(childrenList[4])

© Stack Overflow or respective owner

Related posts about pyqt

Related posts about qt