[PyQt] QTreeWidget and XML: Index example

Gustavo A. Díaz gustavo.diaz at gmail.com
Thu May 22 19:57:43 BST 2008


Hi Guys,

I am coding a documentation  dialog for my applicacion.
I am "trying" to implement and index with XML and QTreeWidget. The XML file
already exist, so is not being created by code. My idea is, that every item
of that index should have an html assigned (i using webView to parse the
html) and when i click on that index item, should show the html. The part of
the webView is not the poblem for me. But i dont know how exactly create the
code for the index with QTreeView and XML.

I already show the index in QTreeWidget with this method:

def loadIndex(self):

  # Abrimos el archivo XML
  self.indexFile = QFile('core/documentation/html/index.xml')
  self.indexFile.open(QIODevice.ReadOnly)

  # Cargamos el encabezado del XML y el contenido
  self.document = QDomDocument("DOCSINDEX")
  self.document.setContent(self.indexFile)

  # Cerramos el archivo XML
  self.indexFile.close()

  # Denominación del delemento dentro del XML
  self.docElem = self.document.documentElement()

  # Comenzamos a leer el contenido del XML
  self.node = self.docElem.firstChild()
  while(self.node.isNull() == False):
  self.element = self.node.toElement() # intenta convertir el nodo en un
elemento.

  if(self.element.isNull() == False):
  if(self.element.tagName() == 'father'):
  self.itemTreeFather = QtGui.QTreeWidgetItem(self.indexTreeWidget)
  self.itemTreeFather.setText(0,self.element.text())

  if(self.element.tagName() == 'son'):
  self.itemTreeSon = QtGui.QTreeWidgetItem(self.itemTreeFather)
  self.itemTreeSon.setText(0,self.element.text())

  if(self.element.tagName() == 'grandson'):
  self.itemTreeGrandson = QtGui.QTreeWidgetItem(self.itemTreeSon)
  self.itemTreeGrandson.setText(0,self.element.text())

  self.node = self.node.nextSibling()


But from this point, i dont know to link every item of the xml to the
corresponding html file.
I was searching in the net about some "clearly" example of index using this
method but with no  luck so far.

If someone could give me a little tip or starting point, i would be
gratefull.

Cheers.

-- 
Gustavo A. Díaz
GDNet Projects
www.gdnet.com.ar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080522/06d80db4/attachment-0001.html


More information about the PyQt mailing list