Question

s = 'someString'
s = QTreeWidgetItem(s)
print(s.text(0))           # 0 being 'column'

Output:

's'

It also appears as 's' if I run 'addChild(s)' to another QTreeWidgetItem.

Was it helpful?

Solution

QTreeWidgetItem construct is meant to be passed multiple strings (not a single one):

>>> s = QTreeWidgetItem(['someString', 'otherString'])
>>> print(s.text(0))
someString
>>> print(s.text(1))
otherString

Passing a single string object 'someString' is like passing a sequence with multiple single-character strings ['s', 'o', 'm', 'e', 'S', 't', 'r', 'i', 'n', 'g'].

If you want pass a single string, wrap in list or tuple:

s = QTreeWidgetItem(['someString'])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top