How to select this element in Qtreewidget using the path to an element?
How to select this element in Qtreewidget using the path to an element?
The path is written as an example string:
parent/parent/parent/parent/element
I create a tree from the list of similar cloths in this way:
def makeTree(self):
self.treeWidget.clear()
data = talkToViz(SimpleLabels.IPSerwer)
FunctionsWindow.dataGlobal = data
treeWidget = self.treeWidget
items = {}
def makeChild(parentPath, name):
if '^^^' in name:
FunctionsWindow.colorRow = True
name = name.replace('^^^', '')
if parentPath in items:
parent = items[parentPath]
else:
if not parentPath:
parent = items[''] = treeWidget
else:
splitPath = parentPath.split('/')
parent = makeChild('/'.join(splitPath[:-1]), splitPath[-1])
if parentPath:
itemPath = parentPath + '/' + name
else:
itemPath = name
item = items[itemPath] = QTreeWidgetItem(parent, [name])
if FunctionsWindow.colorRow == True:
item.setForeground(0, QtGui.QBrush(QtGui.QColor("#084ad9")))
self.comboBox_Scene.addItem(str(itemPath), None)
FunctionsWindow.colorRow = False
return item
for item in data:
splitPath = item.split('/')
makeChild('/'.join(splitPath[:-1]), splitPath[-1])
source https://stackoverflow.com/questions/77848555/how-to-find-element-in-qtreewidget-in-python
Comments
Post a Comment