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

有帮助吗?

解决方案

QTreeWidgetItem constructor expects a list of strings. Try this:

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

其他提示

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")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top