PDA

View Full Version : Treeview with buttons



galactor88
14th July 2009, 09:31
I'm looking for a way to get buttons (or other controls) in one of the columns of the treeView.
Currently i'm using a QtreeView and have the QStandardItemModel in use.
I'm able to get a string in the columns, but need a button to be there.

My code is written in python, but it should be fairly easy to read for non python users.

I did look around on google to get this solved, that helped a little bit, but it's a bit to complicated to solve on my own.
Is there anyone that knows how to do this?

The code down here is the procedure that fils the currently created treeView:


def addToList2(self):
model = QtGui.QStandardItemModel(self.treeView)
self.treeView.setModel(model)

model.insertRows(0, 4)
model.insertColumns(0, 4)

row = col = 0
while row < 4:
col = 1
while col < 4:
index = model.index(row, col)
model.setData(index, QtCore.QVariant('X'))
col += 1
row += 1

self.treeView.show()

spirit
14th July 2009, 09:33
I don't understand, do you need buttons in a header of a treeView or buttons as items of a treeView?

galactor88
14th July 2009, 09:54
This is what i'm trying to build:

http://home.hetnet.nl//~p88jansen88/editor.jpg

The red/green/yellow and blue squares would represent buttons that perform a task on the file it shares a row with.

spirit
14th July 2009, 09:55
I see, then take a look at QItemDelegate.