QComboBox中的PyQt启用/禁用元素

2024-03-29 08:29:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个QComboBox,它列出了所有Windows的驱动器号,让用户从中进行选择。 在执行过程中,我们需要启用或禁用一些字母(不移除它们)。

以下是基本代码:

all_letters = ["{}:".format(chr(i)) for i in range(90, 64, -1)]  # Z: -> A:
all_letters.insert(0, "")
cb_letter = QtGui.QComboBox()
for l in all_letters:
    cb_letter.addItem(l)
cb_letter.setCurrentIndex(0)

我可以找到一种解决方案(听起来很复杂),只需禁用一个条目here,但无法重新启用它。

启用和禁用QComboBox的任何条目的最佳方法是什么?


Tags: 代码用户informatfor过程windows字母