PyQT5 QComboBox - get value of combobox

寵の児 提交于 2019-12-01 00:25:00

You can use addItem to add a name (text) with an associated value (data):

    self.combo.addItem('Foo', 23)
    self.combo.addItem('Bar', 42)

A slot can be connected to the activated signal of the combo box, which will send the index of the item selected by the user:

    self.combo.activated.connect(self.handleActivated)

You can then use itemText and itemData to access the name and value via the index parameter:

    def handleActivated(self, index):
        print(self.combo.itemText(index))
        print(self.combo.itemData(index))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!