Qcombobox犯错了索引
我有这个组合。
klients = qtw.QComboBox(self)
klients.insertItem(5, "x")
klients.insertItem(19, "y")
当我以后在按钮单击事件中编写此代码时:
print(klients.currentIndex())
它打印0或1而不是5或19。如何实现它打印5或19?
I have this combobox.
klients = qtw.QComboBox(self)
klients.insertItem(5, "x")
klients.insertItem(19, "y")
when I later write this code in button clicked event:
print(klients.currentIndex())
It prints 0 or 1 instead of 5 or 19. How can I achieve it prints 5 or 19?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
qcombobox项目管理就像一个列表一样工作:创建新列表后,执行
list.intert(5,“ x”)
将在 first index上添加“ x”,这很明显,因为列表为空。如果要具有自定义数据的内部引用,请使用
userData
additem()
:然后用
currentdata()
:QComboBox item management works just like a list: after creating a new list, doing
list.insert(5, "x")
will add "x" at the first index, which is quite obvious, since the list is empty.If you want to have internal reference of custom data, then use the
userData
argument ofaddItem()
:and then retrieve it with
currentData()
: