I can\'t find a standard way to disable an individual item in a Qt combo box. Is there a facility to do this in Qt that I am missing?
Taken from here:
// Get the index of the value to disable
QModelIndex index = ui.comboBox->model()->index(1, 0);
// This is the effective 'disable' flag
QVariant v(0);
// the magic
ui.comboBox->model()->setData(index, v, Qt::UserRole - 1);
To enable again use:
QVariant v(1 | 32);
The model used maps the flags
word to Qt::UserRole - 1
-- that's what makes this code work. It's not a generic solution that would work with an arbitrary model.