【问题标题】:how can I get current value to qcombobox in pyqt?如何在 pyqt 中获取 qcombobox 的当前值?
【发布时间】:2015-05-27 02:32:36
【问题描述】:

我需要在我的 qcombobox 中获取选定的值。它是从数据库中填充的,QCombobox 被命名为 cbUser 这是我填充 qcombobox 的函数:

for row in self.SELECT_USERS_ACCOUNTS():
    self.cbUser.addItem(str(row[1]),int(row[0]))

数据在qcombobox cbUser中显示成功。 我得到一个函数来获取所选项目的值:

def getValue(self):
    id_us = self.cbUser.itemData(self.cbUser.currentIndex())
    print(str(id_us))

打印显示的不是数据,正确的数据是整数值,例如 1 或 2 .... 请帮助我,提前谢谢。

更新: 解决方法是将第一行代码修改为getValue函数(添加.toPyObject()):

id_us = self.cbUser.itemData(self.cbUser.currentIndex()).toPyObject()

【问题讨论】:

  • 我添加了 toPyObject 并得到了它。 id_us = self.cbUser.itemData(self.cbUser.currentIndex()).toPyObject()

标签: python-2.7 pyqt qcombobox


【解决方案1】:

解决方法是将第一行代码修改为getValue函数(添加.toPyObject()):

id_us = self.cbUser.itemData(self.cbUser.currentIndex()).toPyObject()

通过这个我看到了存储在 qcombobox 中的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-27
    • 2011-08-29
    • 2016-02-29
    • 1970-01-01
    • 2011-02-10
    • 2014-11-13
    • 2012-11-13
    • 2011-05-27
    相关资源
    最近更新 更多