如何创建xml文件包含由用户创建的QTreeWidgetItem的级别层次结构,我使用(ETreeElement用于创建xml文件)?我尝试通过使xml文件获取结构来实现此目的在用户创建它但我只有第一个孩子的根项目我不能得到其他项目
def rootItem(self):
itemName = self.TreeviewForFolders.topLevelItem(0).text(0)
return itemName
def addItem(self, name, parent):
self.TreeviewForFolders.expandItem(parent)
item = QTreeWidgetItem(parent)
item.setText(0,name)
item.setFlags(Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled)
return item
def addFolders(self):
item = self.TreeviewForFolders.invisibleRootItem()
if(self.TreeviewForFolders.topLevelItemCount() == 0):
self.addItem("Item", item)
root = Element(str(self.rootItem()))
else:
if(len(self.TreeviewForFolders.selectedItems()) > 0):
item = self.TreeviewForFolders.selectedItems()[0]
self.addItem("Item", item)
root = Element(str(self.rootItem()))
child = SubElement(root, "Item")
output_file = open( 'Tamplet.xml', 'w' )
output_file.write( '<?xml version="1.0"?>' )
output_file.write( ElementTree.tostring( root ) )
output_file.close()
答案 0 :(得分:0)