Skip to content Skip to sidebar Skip to footer

Multiple Columns In PyQt4 (potentially Using QTreeWidget)

I'm trying to get QTreeWidget working exactly similar to this one. In python! I don't care about multiple tabs but about multiple columns. This is what I've got so far. I don't k

Solution 1:

There's a few things you'll want to fix there.

from PyQt4 import QtCore, QtGui
import sys

app = QtGui.QApplication(sys.argv)
QtGui.qApp = app

pointListBox = QtGui.QTreeWidget()

header=QtGui.QTreeWidgetItem(["Tree","First","secondo"])
#...
pointListBox.setHeaderItem(header)   #Another alternative is setHeaderLabels(["Tree","First",...])

root = QtGui.QTreeWidgetItem(pointListBox, ["root"])
A = QtGui.QTreeWidgetItem(root, ["A"])
barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"])
bazA = QtGui.QTreeWidgetItem(A, ["baz", "a", "b"])


pointListBox.show()
sys.exit(app.exec_())

I didn't finish the example, but that should get you reasonably close.

Note that instead of barA = QtGui.QTreeWidgetItem(A, ["bar", "i", "ii"]), there's nothing wrong with

barA = QtGui.QTreeWidgetItem(A)
barA.setText(0,"bar")
barA.setText(1,"i")
barA.setText(2,"ii")

if you need to calculate something before displaying the text.


Post a Comment for "Multiple Columns In PyQt4 (potentially Using QTreeWidget)"