QT QCombBox 控件设置下拉选项中某项不可选

QComboBox *editor = new QComboBox(this);
comboBox->addItems(QStringList()<<tr("Always")<<tr("Never")<<tr("Motion detection")<<tr("Timer recording"));
QVariant v(0);
// 序号为2的选项(第三个)不可选
comboBox->setItemData(2, v, Qt::UserRole - 1);
// 选项背景置灰
comboBox->setItemData(2, Qt::lightGray, Qt::BackgroundColorRole);
return editor;

posted @ 2018-09-26 14:45  进击的小海绵  阅读(3313)  评论(0)    收藏  举报