gpt4 book ai didi

python - pyside/pyqt : when converting str() to QTreeWidgetItem() the str() is shortened to the [0] of str()

转载 作者:行者123 更新时间:2023-12-01 05:22:01 29 4
gpt4 key购买 nike

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

输出:

's'

如果我对另一个 QTreeWidgetItem 运行“addChild(s)”,它也会显示为“s”。

最佳答案

QTreeWidgetItem construct意味着传递多个字符串(而不是单个字符串):

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

传递单个字符串对象'someString'就像传递具有多个单字符字符串的序列['s', 'o', 'm', 'e', ' S'、't'、'r'、'i'、'n'、'g']

如果您想传递单个字符串,请包装在列表或元组中:

s = QTreeWidgetItem(['someString'])

关于python - pyside/pyqt : when converting str() to QTreeWidgetItem() the str() is shortened to the [0] of str(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127245/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com