samb samb - 8 months ago 64
Python Question

PyQt Enable/Disable elements in a QComboBox

I have a QComboBox that list all Windows' drive letters and let the user choose among them.
During the execution, we need to enable or disable some of the letters (without removing them).

Here is the basic code :

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:

I could find a kind of solution (which sounds really complicated) for just disabling an entry here but no way to enable it back.

What would be the best way to enable and disable any entry of a QComboBox?

Answer Source

By default, QComboBox uses a QStandardItemModel, so all of the convenience methods of QStandardItem are available to you: