【问题标题】:How to add value to each Item in QComboBox [duplicate]如何为 QComboBox 中的每个项目添加价值 [重复]
【发布时间】:2019-12-08 05:35:09
【问题描述】:

我正在与QComboBoxPyQt5 合作。我希望QComboBox 中的每个项目都保存一个值。为了证明我的想法,我的 firstC 中有 3 个项目,名为 USD, EUR, BGN

我希望每个项目都有一个值,例如 USD 能够在控制台上 print('1'),第二个项目到 (EUR) print('2') 等等...

My idea behind this is, when an Item in the QComboBox is selected, to hold a value.

【问题讨论】:

    标签: python pyqt qcombobox


    【解决方案1】:

    您是否研究过 QComboBox 的“ItemData”方法? 您可以使用combobox.setItemData(intex, value[, role]) 和类似的getItemDataitemData

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 2021-04-12
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      相关资源
      最近更新 更多