PDA

View Full Version : Question about QTreeWidgetItem



perny
24th March 2010, 17:39
Hi there,
I've a small problem with nested QTreeWidgetItem.
Basically I have a list of elements in a QTreeWidge and I would like to link one of them to a sub-list.
Look at this small and easy example:
************************************************** **
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Form(QDialog):
def __init__(self):
QDialog.__init__(self)
self.resize(350, 150)
self.tree = QTreeWidget()
self.tree.setColumnCount(3)
self.tree.setHeaderLabels(["first", "second", "third"])

def addEntryInTree(self, a, b, c):
item = QTreeWidgetItem(self.tree)
item.setText(0, a)
item.setText(1, b)
item.setText(2, c)
return item

def addInfoInTree(self, item, text, pos=0):
for i in range(2):
j = QTreeWidgetItem(item)
j.setText(pos, text)

def show(self):
grid = QGridLayout()
grid.addWidget(self.tree)
self.setLayout(grid)
QDialog.show(self)


app = QApplication([])
form = Form()
item = form.addEntryInTree("this is", "just", "a line")
form.addInfoInTree(item, "xxxxx")
item = form.addEntryInTree("this is", "another", "line")
form.addInfoInTree(item, "yyyyy", 1)
form.show()
app.exec_()
************************************************** **
This example will show the following image:
http://old.nabble.com/file/p28017133/example1.jpg
What I'm trying to achieve is to "move" the (-)/(+) signs to the second column. As you can see the position of the actual content can be triggered by the variable 'pos' but I would like to change the complete root of the structure.
I hope it's clear... anyway, the end result should be something like this:
http://old.nabble.com/file/p28017133/example2.jpg
I did that manually dragging the third column over the first one. Actually, this might be a solution too but I couldn't find a way to swap columns too (although there is the method "columnMoved ()" which is called whenever this action is performed).

Can anyone help me?
Perny