0

Im learning how to use QTreeWidget and Im stuck adding new items to it. The QTreewidget itself is created with qtdesigner, so my idea was just to add items. eg:

tw = self.ui.treeWidget
item = QtGui.QTreeWidgetItem("TEST")
tw.addTopLevelItem(item)

But in the treewidget only appears the first letter of "TEST". Doesnt matter what I type, it always only displays the first letter and I have no idea why...

tree

Hubschr
  • 1,285
  • 6
  • 18
  • 35
  • I haven't been coding in Qt for quite some time now, but my first inclination is to check the dimensions and size rules on whatever "TEST" is to be rendered in, and then dimensions and size rules on whatever that is to be rendered in, etc. – San Jacinto Apr 10 '14 at 11:49

2 Answers2

3

QTreeWidgetItem constructor expects a list of strings. Try this:

tw = self.ui.treeWidget
item = QtGui.QTreeWidgetItem(["TEST"])
tw.addTopLevelItem(item)
bosnjak
  • 8,424
  • 2
  • 21
  • 47
2

The QtGui.QTreeWidgetItem is expecting a list for different columns. You can simply wrap your text in a list

item = QtGui.QTreeWidgetItem(["TEST"])

or you can set the text for a specific column.

item = QtGui.QTreeWidgetItem()
item.setText(0, "TEST")
justengel
  • 6,132
  • 4
  • 26
  • 42