Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:
    cb_letter.addItem(l)
cb_letter.setCurrentIndex(0)

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?

like image 835
samb Avatar asked Apr 30 '15 14:04

samb


1 Answers

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

cb_letter.model().item(2).setEnabled(False)
like image 118
ekhumoro Avatar answered Oct 20 '22 00:10

ekhumoro