Details
-
Suggestion
-
Resolution: Done
-
Not Evaluated
-
None
-
None
-
360df2cf74410b05d1cab0192f2d0ff5a39db59e (qt/qtbase/5.15)
Description
Under some circumstances, it it desireable to hide a QComboBox item. E. g. if one wants to make a selection mandatory, one would like to add a dummy item which is selected by default but can't be selected by the user (like "choose one" or such), and as long as this one is selected, one can't e. g. press a "Proceed" button.
Currently, this can be achieved, but in a quite inconvenient, non-obvious way. One has to do the following:
// Cf. https://stackoverflow.com/questions/25172220/
// Hide it in the popup
QListView *view = qobject_cast<QListView *>(combo->view());
Q_ASSERT(view != nullptr);
view->setRowHidden(row, true);
// Make it unaccessible for mouse wheel and arrow keys selection
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(combo->model());
Q_ASSERT(model != nullptr);
QStandardItem *item = model->item(row);
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
It would be nice if a QComboBox had a function like QComboBox::hideItem(int index) or such to do this.
Attachments
Issue Links
- duplicates
-
QTBUG-1556 Support "instruction"-item in QComboBox
-
- Closed
-