PDA

View Full Version : QCombobox - disable an item but still retain it in the list



OzQTNoob
19th March 2012, 04:15
is it possible to disable a single item (or more if I so choose) in a QCombobox.

I do not want to remove an item from the list just gray it out or so it cant be selected.

aamer4yu
19th March 2012, 13:41
May be you can try -
Setting your own view ( QListWidget ) to the combobox and then disabling the items you want with setItemFlags.

Other way would be by accessing the item through combobox's model and setting the enabled flag. Am looking for a way to do this.. will post if I find.
Till then you can try the above method :)

Added after 14 minutes:

Well, found something,-


void QStandardItem::setFlags(Qt::ItemFlags flags)
{
setData((int)flags, Qt::UserRole - 1);
}


So you can try the following -
QComboBox::setItemData(row,false, Qt::UserRole - 1);

I guess it should work...

zgulser
19th March 2012, 14:04
you can edit the color(i.e. for convinience gray tones) of your item you disabled and doing nothing upon it's selection.