Hello all,
I have run into a problem with my application. I need to be able to restore
the hierarchy as it is after I clear it and repopulate the list.
My current solution is to run through the items in the treewidget and
gather the list of indexes like so. I then iterate through the tree once it
has been cleared and repopulated and try to match up the indexes with the
old list:
It does not work, I believe that the indexes are changed on the refresh for
each item which is problematic, is there any way to keep the index of each
consistent?
I have come across persistent indexes but that is for QAbstractModel and I
am using QtreeWidget, I am unsure if the underlying model o fmy treewidget
is a QAbstractModel and if I can use persistent indexes.
def refreshWidget(self, filePath, xmlTree, displayWidget, fileType):
saveState = self.saveWidgetState(displayWidget)
config.uiViewCleared = True
displayWidget.clear()
config.uiViewCleared = False
self.xmlI_O.setUpTree(filePath, xmlTree, displayWidget,
fileType)
self.loadWidgetState(displayWidget, saveState)
def saveWidgetState(self, displayWidget):
print displayWidget.selectionModel()
expandedIndexes = {}
it = QtGui.QTreeWidgetItemIterator(displayWidget)
while it.value():
itemIndex = displayWidget.indexFromItem(it.value(), 0)
expandedItem = displayWidget.isItemExpanded(it.value())
expandedIndexes.update({itemIndex: expandedItem})
it += 1
return expandedIndexes
def loadWidgetState(self, displayWidget, expandedIndexes):
it = QtGui.QTreeWidgetItemIterator(displayWidget)
while it.value():
toExpand = [i for i in expandedIndexes if i ==
displayWidget.indexFromItem(it.value(),0)]
print "toExpand", toExpand
shouldExpand = expandedIndexes.get(toExpand[0])
if shouldExpand == True:
if not displayWidget.isItemExpanded(it.value()):
print "to expand", it.value().text(0)
displayWidget.expandItem(it.value())
it += 1
Cheers!
Ben
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/bab43dd9-65a8-4c27-8a83-45dbfb47c265%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.